[Cbe-oss-dev] [RFC/PATCH 2/2] libspe2: Test for no spe_stop_info_read call case

Kazunori Asayama asayama at sm.sony.co.jp
Wed Jun 4 17:49:16 EST 2008


This patch against the libspe2 test suite adds a new test for the case
when spe_stop_info_call is never called.

Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
 tests/libspe2.event/Makefile                     |    5 -
 tests/libspe2.event/test_event_stop_no_handler.c |  114 +++++++++++++++++++++++
 2 files changed, 118 insertions(+), 1 deletion(-)

Index: b/tests/libspe2.event/Makefile
===================================================================
--- a/tests/libspe2.event/Makefile	2008-06-03 16:52:38.000000000 +0900
+++ b/tests/libspe2.event/Makefile	2008-06-03 16:54:21.000000000 +0900
@@ -29,7 +29,8 @@ main_progs = \
 	test_event_tag_group.elf \
 	test_event_wbox.elf \
 	test_event.elf \
-	test_event_error.elf
+	test_event_error.elf \
+	test_event_stop_no_handler.elf
 
 
 include $(TEST_TOP)/make.rules
@@ -44,6 +45,8 @@ test_event_wbox.elf: spu_event_wbox.embe
 
 test_event.elf: spu_event.embed.o
 
+test_event_stop_no_handler.elf: spu_event_stop.embed.o
+
 spu_ibox.c: ../libspe2.mfc/spu_ibox.c
 	ln -sf $< $@
 
Index: b/tests/libspe2.event/test_event_stop_no_handler.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/tests/libspe2.event/test_event_stop_no_handler.c	2008-06-04 14:57:45.000000000 +0900
@@ -0,0 +1,114 @@
+/*
+ *  libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS
+ *
+ *  Copyright (C) 2008 Sony Computer Entertainment Inc.
+ *  Copyright 2008 Sony Corp.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/* This test checks that the libspe2 doesn't stall even if
+ * spe_stop_info_read is never called.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <pthread.h>
+#include <errno.h>
+#include <string.h>
+
+#include "ppu_libspe2_test.h"
+
+#define COUNT 50000
+
+extern spe_program_handle_t spu_event_stop;
+
+static const spe_stop_info_t expected_stop_info = {
+  .stop_reason = SPE_STOP_AND_SIGNAL,
+  .result.spe_signal_code = STOP_DATA,
+};
+
+static void *spe_thread_proc(void *arg)
+{
+  ppe_thread_t *ppe = (ppe_thread_t*)arg;
+  spe_context_ptr_t spe;
+  unsigned int entry = SPE_DEFAULT_ENTRY;
+  spe_stop_info_t stop_info;
+  int ret;
+  unsigned int i;
+
+  spe = spe_context_create(SPE_EVENTS_ENABLE, NULL);
+  if (!spe) {
+    eprintf("spe_context_create: %s\n", strerror(errno));
+    fatal();
+  }
+
+  if (spe_program_load(spe, &spu_event_stop)) {
+    eprintf("spe[%d]: spe_program_load: %s\n", ppe->index, strerror(errno));
+    fatal();
+  }
+
+  global_sync(NUM_SPES);
+
+  for (i = 0; ; i++) { /* run until the SPE exits */
+    ret = spe_context_run(spe, &entry, 0,
+			  (void*)STOP_DATA, (void*)COUNT, &stop_info);
+    if (ret == 0) { /* exit */
+      if (i != COUNT) {
+	eprintf("spe[%d]: spe_context_run: Unexpected exit\n", ppe->index);
+	fatal();
+      }
+      if (check_exit_code(&stop_info, 0)) {
+	fatal();
+      }
+      break;
+    }
+    else if (ret > 0) { /* user stop code */
+      if (check_stop_info(&stop_info, &expected_stop_info)) {
+	fatal();
+      }
+    }
+    else { /* error */
+      eprintf("spe[%d]: spe_context_run: %s\n", ppe->index, strerror(errno));
+      fatal();
+    }
+  }
+
+  ret = spe_context_destroy(spe);
+  if (ret) {
+    eprintf("spe_context_destroy(%p): %s\n", spe, strerror(errno));
+    fatal();
+  }
+
+  return NULL;
+}
+
+static int test(int argc, char **argv)
+{
+  int ret;
+
+  ret = ppe_thread_group_run(NUM_SPES, spe_thread_proc, NULL, NULL);
+  if (ret) {
+    fatal();
+  }
+
+  return 0;
+}
+
+int main(int argc, char **argv)
+{
+  return ppu_main(argc, argv, test);
+}



More information about the cbe-oss-dev mailing list