[Cbe-oss-dev] [PATCH 2/2] libspe2: Tests for no stop event handler cases (take 2)
Kazunori Asayama
asayama at sm.sony.co.jp
Mon Jun 9 14:06:15 EST 2008
This patch against the libspe2 test suite adds new tests for the cases
when no stop event handler is registered.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
tests/libspe2.event/Makefile | 8 +
tests/libspe2.event/test_event_stop.c | 8 +
tests/libspe2.event/test_event_stop_no_handler.c | 123 +++++++++++++++++++++++
tests/libspe2.event/test_event_stop_no_read.c | 114 +++++++++++++++++++++
4 files changed, 252 insertions(+), 1 deletion(-)
Index: b/tests/libspe2.event/Makefile
===================================================================
--- a/tests/libspe2.event/Makefile 2008-06-06 16:21:05.000000000 +0900
+++ b/tests/libspe2.event/Makefile 2008-06-06 16:40:14.000000000 +0900
@@ -29,7 +29,9 @@ 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_read.elf \
+ test_event_stop_no_handler.elf
include $(TEST_TOP)/make.rules
@@ -44,6 +46,10 @@ test_event_wbox.elf: spu_event_wbox.embe
test_event.elf: spu_event.embed.o
+test_event_stop_no_read.elf: spu_event_stop.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.c
===================================================================
--- a/tests/libspe2.event/test_event_stop.c 2008-04-25 22:43:00.000000000 +0900
+++ b/tests/libspe2.event/test_event_stop.c 2008-06-09 11:41:19.000000000 +0900
@@ -209,6 +209,14 @@ static int test(int argc, char **argv)
for (i = 0; i < NUM_SPES; i++) {
pthread_join(params[i].tid, NULL);
+ event[0].spe = params[i].spe;
+ event[0].events = SPE_EVENT_SPE_STOPPED;
+ ret = spe_event_handler_deregister(evhandler, event);
+ if (ret == -1) {
+ eprintf("spe_event_handler_deregister: %s\n", strerror(errno));
+ fatal();
+ }
+
if (params[i].num_stop > COUNT) {
eprintf("spe[%u]: too many events (%u/%u).\n", i, params[i].num_stop, COUNT);
failed();
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-06 16:39:22.000000000 +0900
@@ -0,0 +1,123 @@
+/*
+ * 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 no stop
+ * event handler is registered.
+ */
+
+#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, stop_info2;
+ 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_stop_info_read(spe, &stop_info2);
+ if (ret != 0) {
+ eprintf("spe[%d]: spe_stop_info_read: Unexpected return code\n", ppe->index, ret);
+ fatal();
+ }
+ if (check_stop_info(&stop_info2, &expected_stop_info)) {
+ 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);
+}
Index: b/tests/libspe2.event/test_event_stop_no_read.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ b/tests/libspe2.event/test_event_stop_no_read.c 2008-06-06 16:30:33.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