Bug 1594 - gcov coverage test support for applications over DCE draft default tip
authorHajime Tazaki <tazaki@nict.go.jp>
Thu, 21 Mar 2013 14:53:47 +0900
changeset 64 06fe4ef443b9
parent 63 7fcf6218ef87
Bug 1594 - gcov coverage test support for applications over DCE
.hgignore
Makefile
sim/include/sim-init.h
sim/sim.c
--- a/.hgignore	Wed Nov 28 15:15:20 2012 +0900
+++ b/.hgignore	Thu Mar 21 14:53:47 2013 +0900
@@ -4,3 +4,4 @@
 ^objdir/
 ^poub
 ^net-next
+\.gcno$
--- a/Makefile	Wed Nov 28 15:15:20 2012 +0900
+++ b/Makefile	Thu Mar 21 14:53:47 2013 +0900
@@ -13,6 +13,11 @@
 proc.c seq.c socket.c tasklet-hrtimer.c \
 cred.c pid.c modules.c
 
+COV?=no
+cov_yes=-fprofile-arcs -ftest-coverage
+cov_no=
+covl_yes=-fprofile-arcs
+covl_no=
 
 OPT?=no
 opt_yes=-O3 -fomit-frame-pointer 
@@ -32,7 +37,8 @@
  -include autoconf.h \
  -U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 \
  -I$(SRCDIR)sim/include -I$(SRCDIR)$(KERNEL_DIR)/include \
- $(PIC_CFLAGS) -D_DEBUG -I`pwd`
+ $(PIC_CFLAGS) -D_DEBUG -I`pwd` $(cov_$(COV))
+
 
 include $(SRCDIR)processor.mk
 
@@ -40,7 +46,7 @@
 CFLAGS+= -DCONFIG_64BIT
 endif
 
-LDFLAGS += -shared -nostdlib -g3 -Wl,-O1 -Wl,-Tlinker.lds 
+LDFLAGS += -shared -nodefaultlibs -g3 -Wl,-O1 -Wl,-Tlinker.lds $(covl_$(COV))
 
 modules:=
 all-obj-for-clean:=
--- a/sim/include/sim-init.h	Wed Nov 28 15:15:20 2012 +0900
+++ b/sim/include/sim-init.h	Thu Mar 21 14:53:47 2013 +0900
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <linux/types.h>
 #include <linux/socket.h>
+#include <stdio.h>
 #include "sim-types.h"
 
 #ifdef __cplusplus
@@ -56,6 +57,20 @@
   void (*free) (struct SimKernel *kernel, void *buffer);
   void *(*memcpy) (struct SimKernel *kernel, void *dst, const void *src, unsigned long size);
   void *(*memset) (struct SimKernel *kernel, void *dst, char value, unsigned long size);
+  int (*atexit) (struct SimKernel *kernel, void (*function)(void));
+  int (*access) (struct SimKernel *kernel, const char *pathname, int mode);
+  char *(*getenv) (struct SimKernel *kernel, const char *name);
+  int (*mkdir)(struct SimKernel *kernel, const char *pathname, mode_t mode);
+  int (*open)(struct SimKernel *kernel, const char *pathname, int flags);
+  int (*__fxstat) (struct SimKernel *kernel, int ver, int fd, void *buf);
+  int (*fseek)(struct SimKernel *kernel, FILE *stream, long offset, int whence);
+  void (*setbuf)(struct SimKernel *kernel, FILE *stream, char *buf);
+  FILE *(*fdopen)(struct SimKernel *kernel, int fd, const char *mode);
+  long (*ftell)(struct SimKernel *kernel, FILE *stream);
+  int (*fclose)(struct SimKernel *kernel, FILE *fp);
+  size_t (*fread)(struct SimKernel *kernel, void *ptr, size_t size, size_t nmemb, FILE *stream);
+  size_t (*fwrite)(struct SimKernel *kernel, const void *ptr, size_t size, size_t nmemb, FILE *stream);
+
   unsigned long (*random) (struct SimKernel *kernel);
   void *(*event_schedule_ns) (struct SimKernel *kernel, __u64 ns, void (*fn) (void *context), void *context,
 			      void (*pre_fn) (void));
--- a/sim/sim.c	Wed Nov 28 15:15:20 2012 +0900
+++ b/sim/sim.c	Thu Mar 21 14:53:47 2013 +0900
@@ -1,6 +1,7 @@
 #include <linux/init.h> // initcall_t
 #include <linux/kernel.h> // SYSTEM_BOOTING
 #include <linux/sched.h> // struct task_struct
+#include <stdio.h>
 #include "sim-init.h"
 #include "sim.h"
 
@@ -113,6 +114,10 @@
 
 static struct SimKernel *g_kernel;
 
+
+static int num_handler = 0;
+void *atexit_list[1024];
+
 void sim_init (struct SimExported *exported, const struct SimImported *imported, struct SimKernel *kernel)
 {
   // make sure we can call the callbacks
@@ -172,6 +177,15 @@
 
   // finally, put the system in RUNNING state.
   system_state = SYSTEM_RUNNING;
+
+  /* XXX handle atexit registration for gcov */
+  int i;
+  for (i = 0; i < 1024; i++)
+    {
+      if (atexit_list [i])
+        g_imported.atexit (g_kernel, (void (*)(void))atexit_list[i]);
+    }
+
 }
 
 
@@ -195,6 +209,74 @@
 {
   return g_imported.memset (g_kernel, dst, value, size);
 }
+int atexit (void (*function)(void))
+{
+  if (g_imported.atexit == 0)
+    {
+      atexit_list[num_handler++] = function;
+      return 0;
+    }
+  else
+    {
+      return g_imported.atexit (g_kernel, function);
+    }
+}
+int access (const char *pathname, int mode)
+{
+  return g_imported.access (g_kernel, pathname, mode);
+}
+char *getenv (const char *name)
+{
+  return g_imported.getenv (g_kernel, name);
+}
+pid_t getpid(void)
+{
+  return (pid_t)0;
+}
+int mkdir(const char *pathname, mode_t mode)
+{
+  return g_imported.mkdir (g_kernel, pathname, mode);
+}
+int open(const char *pathname, int flags)
+{
+  return g_imported.open (g_kernel, pathname, flags);
+}
+int fcntl(int fd, int cmd, ... /* arg */ )
+{
+  return 0;
+}
+int __fxstat (int ver, int fd, void *buf)
+{
+  return g_imported.__fxstat (g_kernel, ver, fd, buf);
+}
+int fseek(FILE *stream, long offset, int whence)
+{
+  return g_imported.fseek (g_kernel, stream, offset, whence);
+}
+long ftell(FILE *stream)
+{
+  return g_imported.ftell (g_kernel, stream);
+}
+void setbuf(FILE *stream, char *buf)
+{
+  return g_imported.setbuf (g_kernel, stream, buf);
+}
+FILE *fdopen(int fd, const char *mode)
+{
+  return g_imported.fdopen (g_kernel, fd, mode);
+}
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+  return g_imported.fread (g_kernel, ptr, size, nmemb, stream);
+}
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+  return g_imported.fwrite (g_kernel, ptr, size, nmemb, stream);
+}
+int fclose(FILE *fp)
+{
+  return g_imported.fclose (g_kernel, fp);
+}
 unsigned long sim_random (void)
 {
   return g_imported.random (g_kernel);