[Cbe-oss-dev] [PATCH 3/5] libspe2: Improve test of PPE assited call

Kazunori Asayama asayama at sm.sony.co.jp
Thu Apr 24 22:41:14 EST 2008


This patch modify the test of PPE assisted call to test:

  - all call numbers
  - invalid arguments

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

---
 tests/libspe2.run/spu_ppe_assisted_call.c  |    2 
 tests/libspe2.run/test_ppe_assisted_call.c |  278 +++++++++++++++++------------
 2 files changed, 165 insertions(+), 115 deletions(-)

Index: b/tests/libspe2.run/test_ppe_assisted_call.c
===================================================================
--- a/tests/libspe2.run/test_ppe_assisted_call.c	2008-04-22 16:02:24.000000000 +0900
+++ b/tests/libspe2.run/test_ppe_assisted_call.c	2008-04-22 22:31:22.000000000 +0900
@@ -35,7 +35,8 @@
 
 extern spe_program_handle_t spu_ppe_assisted_call;
 
-static int run(int (*check_func)(int ret, spe_stop_info_t *stop_info))
+static int run(unsigned int call_num,
+	       int (*check_func)(int ret, spe_stop_info_t *stop_info))
 {
   int ret;
   spe_context_ptr_t spe;
@@ -53,7 +54,7 @@ static int run(int (*check_func)(int ret
     return 1;
   }
 
-  ret = spe_context_run(spe, &entry, 0, NULL, NULL, &stop_info);
+  ret = spe_context_run(spe, &entry, 0, (void*)call_num, NULL, &stop_info);
   ret = (*check_func)(ret, &stop_info);
   if (ret) {
     return 1;
@@ -85,27 +86,6 @@ static int handler_argument(void *ls_bas
   return 0;
 }
 
-static int check_unregistered(int ret, spe_stop_info_t *stop_info)
-{
-  spe_stop_info_t expected;
-
-  if (ret == 0) {
-    eprintf("spe_context_run: Unexpected success.\n");
-    return 1;
-  }
-  if (errno != EFAULT) {
-    eprintf("spe_context_run: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    return 1;
-  }
-  expected.stop_reason = SPE_CALLBACK_ERROR;
-  expected.result.spe_callback_error = -1;
-  if (check_stop_info(stop_info, &expected)) {
-    return 1;
-  }
-  return 0;
-}
-
 static int check_error_value(int ret, spe_stop_info_t *stop_info)
 {
   spe_stop_info_t expected;
@@ -136,159 +116,229 @@ static int check_argument(int ret, spe_s
   return 0;
 }
 
-static int test(int argc, char **argv)
+static int test_invalid(int call_num)
 {
   int ret;
   void *query;
 
-  /* register error conditions */
-
-#if 0
-  ret = spe_callback_handler_register(NULL, CALL_NUM, SPE_CALLBACK_NEW);
-  if (ret == 0) {
-    eprintf("spe_callback_handler_register: Unexpected success.\n");
-    fatal();
+  query = spe_callback_handler_query(call_num);
+  if (query) {
+    eprintf("spe_callback_handler_query: %d: Unexpected success.\n", call_num);
+    return -1;
   }
   if (errno != EINVAL) {
-    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+    eprintf("spe_callback_handler_query: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
-#endif
 
-  ret = spe_callback_handler_register(handler_error, 0, -1);
+  ret = spe_callback_handler_register(handler_error, call_num, SPE_CALLBACK_NEW);
   if (ret == 0) {
-    eprintf("spe_callback_handler_register: Unexpected success.\n");
-    fatal();
+    eprintf("spe_callback_handler_register: %d: Unexpected success.\n", call_num);
+    return -1;
   }
   if (errno != EINVAL) {
-    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+    eprintf("spe_callback_handler_register: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  ret = spe_callback_handler_register(handler_error, -1, SPE_CALLBACK_NEW);
+  ret = spe_callback_handler_deregister(call_num);
   if (ret == 0) {
-    eprintf("spe_callback_handler_register: Unexpected success.\n");
-    fatal();
+    eprintf("spe_callback_handler_deregister: %d: Unexpected success.\n", call_num);
+    return -1;
   }
   if (errno != EINVAL) {
-    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+    eprintf("spe_callback_handler_deregister: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  ret = spe_callback_handler_register(handler_error, 0, SPE_CALLBACK_NEW);
-  if (ret == 0) {
-    eprintf("spe_callback_handler_register: Unexpected success.\n");
-    fatal();
-  }
-  if (errno != EACCES) {
-    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    fatal();
+  return 0;
+}
+
+static int test_used(int call_num)
+{
+  int ret;
+  void *query;
+
+  /* query on registered call num */
+  query = spe_callback_handler_query(call_num);
+  if (!query) {
+    eprintf("spe_callback_handler_query: %d: Unexpected failure: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  ret = spe_callback_handler_register(handler_error, CALL_NUM, SPE_CALLBACK_UPDATE);
+  /* register as used call num */
+  ret = spe_callback_handler_register(handler_error, call_num, SPE_CALLBACK_NEW);
   if (ret == 0) {
-    eprintf("spe_callback_handler_register: Unexpected success.\n");
-    fatal();
+    eprintf("spe_callback_handler_register: %d: Unexpected success.\n", call_num);
+    return -1;
   }
-  if (errno != ESRCH) {
-    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+  if (errno != EACCES) {
+    eprintf("spe_callback_handler_register: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
+  return 0;
+}
 
-  /* deregister error conditions */
-  ret = spe_callback_handler_deregister(-1);
-  if (ret == 0) {
-    eprintf("spe_callback_handler_deregister: Unexpected success.\n");
-    fatal();
+static int test_unused(int call_num)
+{
+  int ret;
+  void *query;
+
+  /* query on unregistered call num */
+  query = spe_callback_handler_query(call_num);
+  if (query) {
+    eprintf("spe_callback_handler_query: %d: Unexpected success.\n", call_num);
+    return -1;
   }
-  if (errno != EINVAL) {
-    eprintf("spe_callback_handler_deregister: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+  if (errno != ESRCH) {
+    eprintf("spe_callback_handler_query: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  ret = spe_callback_handler_deregister(CALL_NUM);
+  /* update unused call num */
+  ret = spe_callback_handler_register(handler_error, call_num, SPE_CALLBACK_UPDATE);
   if (ret == 0) {
-    eprintf("spe_callback_handler_deregister: Unexpected success.\n");
-    fatal();
+    eprintf("spe_callback_handler_register: %d: Unexpected success.\n", call_num);
+    return -1;
   }
   if (errno != ESRCH) {
-    eprintf("spe_callback_handler_deregister: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
-  }
-
-  /* register, deregister and run */
-  ret = run(check_unregistered);
-  if (ret) {
-    fatal();
+    eprintf("spe_callback_handler_register: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  query = spe_callback_handler_query(-1);
+  /* make sure that 'handler_error' is not registered */
+  query = spe_callback_handler_query(call_num);
   if (query) {
-    eprintf("spe_callback_handler_query: Unexpected success.\n");
-    fatal();
+    eprintf("spe_callback_handler_query: %d: Unexpected success.\n", call_num);
+    return -1;
   }
-  if (errno != EINVAL) {
-    eprintf("spe_callback_handler_query: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+  if (errno != ESRCH) {
+    eprintf("spe_callback_handler_query: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  query = spe_callback_handler_query(CALL_NUM);
-  if (query) {
-    eprintf("spe_callback_handler_query: Unexpected success.\n");
-    fatal();
+  /* unregister unused handler */
+  ret = spe_callback_handler_deregister(call_num);
+  if (ret == 0) {
+    eprintf("spe_callback_handler_deregister: %d: Unexpected success.\n", call_num);
+    return -1;
+  }
+  if (errno == EACCES) { /* reserved call num */
+    return 0;
   }
   if (errno != ESRCH) {
-    eprintf("spe_callback_handler_query: Unexpected errno: %d (%s)\n",
-	    errno, strerror(errno));
-    failed();
+    eprintf("spe_callback_handler_deregister: %d: Unexpected errno: %d (%s)\n",
+	    call_num, errno, strerror(errno));
+    return -1;
   }
 
-  ret = spe_callback_handler_register(handler_error, CALL_NUM, SPE_CALLBACK_NEW);
+  /*** normal conditions ***/
+  ret = spe_callback_handler_register(handler_error, call_num, SPE_CALLBACK_NEW);
   if (ret) {
     perror("spe_callback_handler_register");
-    fatal();
+    return -1;
   }
 
-  query = spe_callback_handler_query(CALL_NUM);
+  query = spe_callback_handler_query(call_num);
   if (!query) {
-    perror("spe_callback_handler_query");
-    fatal();
+    eprintf("spe_callback_handler_query: %d: %s\n", call_num, strerror(errno));
+    return -1;
   }
   if (query != handler_error) {
-    eprintf("spe_callback_handler_query: Unexpected result %p\n", query);
-    failed();
+    eprintf("spe_callback_handler_query: %d: Unexpected result %p\n", call_num, query);
+    return -1;
   }
 
-  ret = run(check_error_value);
+  ret = run(call_num, check_error_value);
   if (ret) {
-    fatal();
+    return -1;
   }
 
-  ret = spe_callback_handler_register(handler_argument, CALL_NUM, SPE_CALLBACK_UPDATE);
+  ret = spe_callback_handler_register(handler_argument, call_num, SPE_CALLBACK_UPDATE);
   if (ret) {
-    perror("spe_callback_handler_register");
-    fatal();
+    eprintf("spe_callback_handler_register: %d: %s\n", call_num, strerror(errno));
+    return -1;
   }
 
-  ret = run(check_argument);
+  ret = run(call_num, check_argument);
   if (ret) {
-    fatal();
+    return -1;
   }
 
-  ret = spe_callback_handler_deregister(CALL_NUM);
+  ret = spe_callback_handler_deregister(call_num);
   if (ret) {
-    perror("spe_callback_handler_deregister");
+    eprintf("spe_callback_handler_deregister: %d: %s\n", call_num, strerror(errno));
+    return -1;
+  }
+
+  return 0;
+}
+
+static int test(int argc, char **argv)
+{
+  int ret;
+  int i;
+
+  /* invalid handler */
+  ret = spe_callback_handler_register(NULL, CALL_NUM, SPE_CALLBACK_NEW);
+  if (ret == 0) {
+    eprintf("spe_callback_handler_register: Unexpected success.\n");
+    fatal();
+  }
+  if (errno != EINVAL) {
+    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
+	    errno, strerror(errno));
+    failed();
+  }
+
+  /* invalid mode */
+  ret = spe_callback_handler_register(handler_error, CALL_NUM, -1);
+  if (ret == 0) {
+    eprintf("spe_callback_handler_register: Unexpected success.\n");
     fatal();
   }
+  if (errno != EINVAL) {
+    eprintf("spe_callback_handler_register: Unexpected errno: %d (%s)\n",
+	    errno, strerror(errno));
+    failed();
+  }
+
+  /* walk through all call num */
+  for (i = -1; i <= 256; i++) {
+    void *query;
+
+    switch (i) {
+    case -1:
+    case 256:
+      ret = test_invalid(i);
+      break;
+    case 0:
+      ret = test_used(i);
+      break;
+    case CALL_NUM:
+      ret = test_unused(i);
+      break;
+    case 4:
+      continue; /* handled by the kernel */
+    default:
+      query = spe_callback_handler_query(i);
+      ret = query ? test_used(i) : test_unused(i);
+      break;
+    }
+
+    if (ret) {
+      fatal();
+    }
+  }
 
   return 0;
 }
Index: b/tests/libspe2.run/spu_ppe_assisted_call.c
===================================================================
--- a/tests/libspe2.run/spu_ppe_assisted_call.c	2008-04-22 16:02:24.000000000 +0900
+++ b/tests/libspe2.run/spu_ppe_assisted_call.c	2008-04-22 17:29:10.000000000 +0900
@@ -30,7 +30,7 @@ int main(unsigned long long spe,
 	 unsigned long long argp, unsigned long long envp)
 {
   __vector unsigned int prog = {
-    PPE_ASSISTED_CALL_SIGNAL_TYPE, /* stop instruction */
+    (unsigned int)(argp + 0x2100), /* stop instruction */
     PPE_ASSISTED_CALL_DATA,        /* test data */
     0x4020007f, /* nop */
     0x35000000  /* bi $0 */




More information about the cbe-oss-dev mailing list