[Cbe-oss-dev] [PATCH 2/5] libspe2: Add tests of image handling in error conditions
Kazunori Asayama
asayama at sm.sony.co.jp
Thu Apr 24 22:39:36 EST 2008
This patch adds tests of SPE program image handling functions in error
conditions to the libspe2 test suite.
Signed-off-by: Kazunori Asayama <asayama at sm.sony.co.jp>
---
tests/common/ppu_file.c | 2
tests/libspe2.run/Makefile | 20 ++++
tests/libspe2.run/test_image_error.c | 145 +++++++++++++++++++++++++++++++++++
tests/libspe2.run/test_run_image.c | 8 -
4 files changed, 163 insertions(+), 12 deletions(-)
Index: b/tests/common/ppu_file.c
===================================================================
--- a/tests/common/ppu_file.c 2008-04-24 21:21:06.000000000 +0900
+++ b/tests/common/ppu_file.c 2008-04-24 21:21:57.000000000 +0900
@@ -92,7 +92,7 @@ int dummy_file_open_r(int num)
close(g_dummy_fd[g_num_dummy_fd]);
}
- return 0;
+ return g_num_dummy_fd;
}
/* close all dummy files */
Index: b/tests/libspe2.run/Makefile
===================================================================
--- a/tests/libspe2.run/Makefile 2008-04-24 21:21:06.000000000 +0900
+++ b/tests/libspe2.run/Makefile 2008-04-24 21:21:57.000000000 +0900
@@ -33,6 +33,7 @@ main_progs = \
test_single_gang_context.elf \
test_context_create_error.elf \
test_run_error.elf \
+ test_image_error.elf \
test_ppe_assisted_call.elf
ifeq ($(TEST_AFFINITY),1)
@@ -41,12 +42,15 @@ main_progs += \
test_affinity_error.elf
endif
-ppu_progs = \
- spu_arg.spu.elf
+ppu_progs =
spu_progs = \
+ spu_arg.spu.elf \
+ spu_null.spu.elf \
spu_spin.spu.elf \
- spu_hello.spu.elf
+ spu_hello.spu.elf \
+ spu_non_exec.spu.elf \
+ spu_non_elf.spu.elf
include $(TEST_TOP)/make.rules
@@ -67,3 +71,13 @@ test_run_error.elf: spu_halt.embed.o spu
spu_invalid_channel.embed.o spu_dma_error.embed.o spu_invalid_dma.embed.o
test_ppe_assisted_call.elf: spu_ppe_assisted_call.embed.o
+
+spu_non_exec.spu.elf: spu_null.spu.elf
+ cp $< $@.tmp
+ chmod -x $@.tmp
+ mv $@.tmp $@
+
+spu_non_elf.spu.elf:
+ dd if=/dev/zero of=$@.tmp bs=1048576 count=16
+ chmod 755 $@.tmp
+ mv $@.tmp $@
Index: b/tests/libspe2.run/test_run_image.c
===================================================================
--- a/tests/libspe2.run/test_run_image.c 2008-04-24 21:21:06.000000000 +0900
+++ b/tests/libspe2.run/test_run_image.c 2008-04-24 21:21:57.000000000 +0900
@@ -37,18 +37,10 @@ static int test(int argc, char **argv)
unsigned int entry = SPE_DEFAULT_ENTRY;
int ret;
char *elf_filename;
- char *dummy_elf_filename;
spe_stop_info_t stop_info;
- dummy_elf_filename = argv[0];
elf_filename = (argc > 1) ? argv[1] : SPE_ELF;
- prog = spe_image_open(dummy_elf_filename);
- if (prog) {
- eprintf("spe_image_open: Unexpected success.\n");
- fatal();
- }
-
prog = spe_image_open(elf_filename);
if (!prog) {
perror("spe_image_open");
Index: b/tests/libspe2.run/test_image_error.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ b/tests/libspe2.run/test_image_error.c 2008-04-24 21:20:59.000000000 +0900
@@ -0,0 +1,145 @@
+/*
+ * 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 if the library can handle errors in the
+ * spe_image_* functions correctly.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "ppu_libspe2_test.h"
+
+#define COUNT 1000
+
+#define NON_EXEC_FILE "spu_non_exec.spu.elf" /* SPU ELF, no permission */
+#define NON_ELF_FILE "spu_non_elf.spu.elf" /* non-ELF format */
+#define NON_SPU_ELF_FILE argv[0] /* PPU ELF */
+
+int main(int argc, char **argv)
+{
+ spe_program_handle_t *prog;
+ int i;
+ int avail_fds, num_fds;
+ int ret;
+
+ /* count # of available file descriptors */
+ avail_fds = dummy_file_open_r(0);
+ if (avail_fds == -1) {
+ eprintf("dummy_file_open_r(0): %s\n", strerror(errno));
+ fatal();
+ }
+ dummy_file_close();
+
+
+ /*** try non-executable file ***/
+ for (i = 0; i < COUNT; i++) {
+ prog = spe_image_open(NON_EXEC_FILE);
+ if (prog) {
+ eprintf("spe_image_open(%s): Unexpected success.\n", NON_EXEC_FILE);
+ fatal();
+ }
+ if (errno != EACCES) {
+ eprintf("spe_image_open(%s): Unexpected errno: %d (%s)\n",
+ NON_EXEC_FILE, errno, strerror(errno));
+ fatal();
+ }
+ }
+ /* check FD leaks */
+ num_fds = dummy_file_open_r(0);
+ if (num_fds == -1) {
+ eprintf("dummy_file_open_r(0): %s\n", strerror(errno));
+ fatal();
+ }
+ dummy_file_close();
+ if (num_fds != avail_fds) {
+ eprintf("spe_image_open(%s): FD leaks.\n", NON_EXEC_FILE);
+ fatal();
+ }
+
+
+ /*** try non-ELF file ***/
+ for (i = 0; i < COUNT; i++) {
+ prog = spe_image_open(NON_ELF_FILE);
+ if (prog) {
+ eprintf("spe_image_open(%s): Unexpected success.\n", NON_ELF_FILE);
+ fatal();
+ }
+ if (errno != EINVAL) {
+ eprintf("spe_image_open(%s): Unexpected errno: %d (%s)\n",
+ NON_ELF_FILE, errno, strerror(errno));
+ fatal();
+ }
+ }
+ /* check FD leaks */
+ num_fds = dummy_file_open_r(0);
+ if (num_fds == -1) {
+ eprintf("dummy_file_open_r(0): %s\n", strerror(errno));
+ fatal();
+ }
+ dummy_file_close();
+ if (num_fds != avail_fds) {
+ eprintf("spe_image_open(%s): FD leaks.\n", NON_ELF_FILE);
+ fatal();
+ }
+
+
+ /*** try non-SPU-ELF file ***/
+ for (i = 0; i < COUNT; i++) {
+ prog = spe_image_open(NON_SPU_ELF_FILE);
+ if (prog) {
+ eprintf("spe_image_open(%s): Unexpected success.\n", NON_SPU_ELF_FILE);
+ fatal();
+ }
+ if (errno != EINVAL) {
+ eprintf("spe_image_open(%s): Unexpected errno: %d (%s)\n",
+ NON_SPU_ELF_FILE, errno, strerror(errno));
+ fatal();
+ }
+ }
+ /* check FD leaks */
+ num_fds = dummy_file_open_r(0);
+ if (num_fds == -1) {
+ eprintf("dummy_file_open_r(0): %s\n", strerror(errno));
+ fatal();
+ }
+ dummy_file_close();
+ if (num_fds != avail_fds) {
+ eprintf("spe_image_open(%s): FD leaks.\n", NON_SPU_ELF_FILE);
+ fatal();
+ }
+
+
+ /* try invalid program handle */
+ ret = spe_image_close(NULL);
+ if (ret == 0) {
+ eprintf("spe_image_close(NULL): Unexpected success.\n");
+ fatal();
+ }
+ if (errno != EINVAL) {
+ eprintf("spe_image_close(NULL): Unexpected errno: %d (%s)\n",
+ errno, strerror(errno));
+ fatal();
+ }
+
+ return 0;
+}
More information about the cbe-oss-dev
mailing list