[Cbe-oss-dev] [PATCH 2/2] libspe2: Use configuration file

Kazunori Asayama asayama at sm.sony.co.jp
Fri Apr 11 19:00:21 EST 2008


This patch modify the tests to use configuration file to pass test
parameters instead of command line arguments, in order to make it easy
to create new tests.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>

---
 tests/common/common_libspe2_test.h           |   27 ++++++++++-
 tests/common/ppu_libspe2_test.h              |   15 +++---
 tests/common/ppu_main.c                      |   62 +--------------------------
 tests/libspe2.event/test_event.c             |    4 -
 tests/libspe2.run/test_affinity.c            |    2 
 tests/libspe2.run/test_affinity_error.c      |    2 
 tests/libspe2.run/test_single_gang_context.c |    4 -
 tests/make.rules                             |   11 +---
 8 files changed, 45 insertions(+), 82 deletions(-)

Index: b/tests/make.rules
===================================================================
--- a/tests/make.rules	2008-04-11 15:24:35.000000000 +0900
+++ b/tests/make.rules	2008-04-11 15:24:40.000000000 +0900
@@ -48,14 +48,11 @@ check:
 
 $(checks): check-%: %
 	@[ -n "$(LIBSPE2_LIB)" ] && export LD_LIBRARY_PATH='$(LIBSPE2_LIB)'; \
-	prog=./$<; \
-	opts=" -n $(TEST_ITERATION) -s $(TEST_SPES)"; \
-	[ "$(TEST_VERBOSE)" != 0 ] && opts="$$opts -v"; \
-	echo "$$prog: RUNNING"; \
-	if $$prog $$opts; then \
-		echo "$$prog: PASS"; \
+	echo "$<: RUNNING"; \
+	if ./$<; then \
+		echo "$<: PASS"; \
 	else \
-		echo "$$prog: FAIL"; exit 1; \
+		echo "$<: FAIL"; exit 1; \
 	fi
 
 clean:
Index: b/tests/common/common_libspe2_test.h
===================================================================
--- a/tests/common/common_libspe2_test.h	2008-04-11 15:24:35.000000000 +0900
+++ b/tests/common/common_libspe2_test.h	2008-04-11 16:05:41.000000000 +0900
@@ -26,6 +26,8 @@
 #ifndef __COMMON_LIBSPE2_TEST_H
 #define __COMMON_LIBSPE2_TEST_H
 
+#include "config_libspe2_test.h"
+
 #include <assert.h>
 
 /*** configurations ***/
@@ -35,17 +37,37 @@
 
 
 /*** test parameters ***/
-#define MAX_SPES 64
-#define DEFAULT_NUM_SPES 4
+#ifndef NUM_SPES
+#define NUM_SPES 4
+#endif
 
+#ifndef WBOX_DEPTH
 #define WBOX_DEPTH 4
+#endif
+
+#ifndef MBOX_DEPTH
 #define MBOX_DEPTH 1
+#endif
+
+#ifndef IBOX_DEPTH
 #define IBOX_DEPTH 1
+#endif
+
+#ifndef MFC_COMMAND_QUEUE_DEPTH
 #define MFC_COMMAND_QUEUE_DEPTH 16
+#endif
+
+#ifndef MFC_PROXY_COMMAND_QUEUE_DEPTH
 #define MFC_PROXY_COMMAND_QUEUE_DEPTH 8
+#endif
 
+#ifndef MAX_DMA_SIZE
 #define MAX_DMA_SIZE (1024 * 16)
+#endif
 
+#ifndef NUM_ITERATIONS
+#define NUM_ITERATIONS 1
+#endif
 
 /*** test data ***/
 #define RUN_ARGP_DATA 0x12345678
@@ -61,7 +83,6 @@
 #define SPE_INVALID_INSTR_OPCODE 0x800000
 #define MFC_INVALID_COMMAND_OPCODE 0x7fff
 
-#define MAX_WBOX_COUNT  (WBOX_DEPTH * 2)
 #define MAX_MBOX_COUNT  WBOX_DEPTH
 
 
Index: b/tests/common/ppu_libspe2_test.h
===================================================================
--- a/tests/common/ppu_libspe2_test.h	2008-04-11 15:24:35.000000000 +0900
+++ b/tests/common/ppu_libspe2_test.h	2008-04-11 15:24:40.000000000 +0900
@@ -36,11 +36,6 @@
 extern int ppu_main(int argc, char **argv, int (*test_proc)(int targc, char **targv));
 
 
-/*** parameters  ***/
-/* # of SPEs to be used (some tests ignore this value) */
-extern int NUM_SPES;
-
-
 /*** error handling and messages ***/
 /* counter to manage number of errors */
 extern int g_failed;
@@ -75,13 +70,17 @@ extern int check_exit_code_helper(const 
 extern void print_spe_error_info(spe_context_ptr_t spe);
 
 /* print messages */
-extern int g_verbose_p;
 #define lmessage(f, n, ...) (fprintf(stderr, "%s:%d: ", f, n), fprintf(stderr, __VA_ARGS__))
 #define message(...) lmessage(__FILE__, __LINE__, __VA_ARGS__)
 #define leprintf(...) lmessage(__VA_ARGS__)
 #define eprintf(...) message(__VA_ARGS__)
-#define ltprintf(...) ((void)(g_verbose_p && lmessage(__VA_ARGS__)))
-#define tprintf(...) ((void)(g_verbose_p && message(__VA_ARGS__)))
+#ifdef ENABLE_VERBOSE
+#define ltprintf(...) lmessage(__VA_ARGS__)
+#define tprintf(...) message(__VA_ARGS__)
+#else
+#define ltprintf(...)
+#define tprintf(...)
+#endif
 
 /* convert enum values into human readable strings */
 extern const char *mbox_behavior_symbol(unsigned int behavior);
Index: b/tests/common/ppu_main.c
===================================================================
--- a/tests/common/ppu_main.c	2008-04-11 15:24:35.000000000 +0900
+++ b/tests/common/ppu_main.c	2008-04-11 15:24:40.000000000 +0900
@@ -28,72 +28,18 @@
 
 #define PROGRESS_STEP 1000
 
-int NUM_SPES = DEFAULT_NUM_SPES;
-int g_verbose_p = 0;
 int g_failed;
 
-static void usage(const char *prog)
-{
-  eprintf("Usage: %s [<options>] [--] [<arguments>]\n"
-	  "Options:\n"
-	  "    -h                 print this message\n"
-	  "    -n <iteration>     repeat test <iteration> times\n"
-	  "    -s <SPEs>          # of SPEs\n"
-	  "    -v                 verbose mode\n"
-	  "    -q                 quiet mode\n"
-	  , prog);
-}
-
 int ppu_main(int argc, char **argv, int (*test_proc)(int targc, char **targv))
 {
-  long long i, iteration = 1;
-  char *str;
-  int c;
-
-  /* parse command line options */
-  while ((c = getopt(argc, argv, "hn:vqs:")) != -1) {
-    switch (c) {
-    case 'h':
-      usage(argv[0]);
-      return 0;
-    case 'n':
-      iteration = strtoll(optarg, &str, 0);
-      if (*str) {
-	usage(argv[0]);
-	return 1;
-      }
-      break;
-    case 's':
-      NUM_SPES = strtol(optarg, &str, 0);
-      if (*str) {
-	usage(argv[0]);
-	return 1;
-      }
-      if (NUM_SPES > MAX_SPES) {
-	eprintf("Too many SPEs\n");
-	return 1;
-      }
-      break;
-    case 'v':
-      g_verbose_p = 1;
-      break;
-    case 'q':
-      g_verbose_p = 0;
-      break;
-    default:
-      usage(argv[0]);
-      return 1;
-    }
-  }
-
-  argv[optind - 1] = argv[0]; /* pass argv[0] as the first parameter of test() */
+  int i;
 
   /* run main test routine in 'iteration' times */
-  for (i = 0; iteration < 0 || i != iteration; i++) {
+  for (i = 0; NUM_ITERATIONS < 0 || i != NUM_ITERATIONS; i++) {
     if (i % PROGRESS_STEP == 0) {
-      tprintf("[%lld/%lld]\n", i, iteration);
+      tprintf("[%d/%d]\n", i, NUM_ITERATIONS);
     }
-    if ((*test_proc)(argc - optind + 1, argv + optind - 1)) {
+    if ((*test_proc)(argc, argv)) {
       return 1;
     }
     check_failed();
Index: b/tests/libspe2.event/test_event.c
===================================================================
--- a/tests/libspe2.event/test_event.c	2008-04-04 20:39:41.000000000 +0900
+++ b/tests/libspe2.event/test_event.c	2008-04-11 15:28:24.000000000 +0900
@@ -218,9 +218,9 @@ static int process_event(const spe_event
 static int test(int argc, char **argv)
 {
   int ret;
-  spe_thread_params_t params[MAX_SPES];
+  spe_thread_params_t params[NUM_SPES];
   spe_event_handler_ptr_t evhandler;
-#define MAX_EVENT (MAX_SPES * 4)
+#define MAX_EVENT (NUM_SPES * 4)
   spe_event_unit_t event[MAX_EVENT];
   int i;
   int exit_count;
Index: b/tests/libspe2.run/test_affinity.c
===================================================================
--- a/tests/libspe2.run/test_affinity.c	2008-04-04 20:39:41.000000000 +0900
+++ b/tests/libspe2.run/test_affinity.c	2008-04-11 15:26:59.000000000 +0900
@@ -77,7 +77,7 @@ static int test_affinity(int mem_p, int 
 
   for (i = 0; i < COUNT; i++) {
     spe_gang_context_ptr_t gang;
-    spe_context_ptr_t spes[MAX_SPES];
+    spe_context_ptr_t spes[NUM_SPES];
     int j;
 
     gang = spe_gang_context_create(0);
Index: b/tests/libspe2.run/test_affinity_error.c
===================================================================
--- a/tests/libspe2.run/test_affinity_error.c	2008-04-04 20:39:41.000000000 +0900
+++ b/tests/libspe2.run/test_affinity_error.c	2008-04-11 15:26:34.000000000 +0900
@@ -61,7 +61,7 @@ static void *spe_thread_proc(void *arg)
 
 static int test(int argc, char **argv)
 {
-  spe_context_ptr_t spes[MAX_SPES];
+  spe_context_ptr_t spes[NUM_SPES];
   spe_gang_context_ptr_t gang;
   spe_gang_context_ptr_t gang2;
   int ret;
Index: b/tests/libspe2.run/test_single_gang_context.c
===================================================================
--- a/tests/libspe2.run/test_single_gang_context.c	2008-04-04 20:39:41.000000000 +0900
+++ b/tests/libspe2.run/test_single_gang_context.c	2008-04-11 15:26:52.000000000 +0900
@@ -65,8 +65,8 @@ static int test(int argc, char **argv)
 {
   int i;
   spe_gang_context_ptr_t gang;
-  spe_context_ptr_t spe[MAX_SPES];
-  pthread_t thr[MAX_SPES];
+  spe_context_ptr_t spe[NUM_SPES];
+  pthread_t thr[NUM_SPES];
   int ret;
 
   gang = spe_gang_context_create(0);



More information about the cbe-oss-dev mailing list