diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2015-07-07 10:03:13 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2015-07-07 10:03:13 +0100 |
commit | c2740578404b4e46d198de70af1cfd554033d99f (patch) | |
tree | bb97478f7d31251d5b1bb0013b6b06b16ca0712c /ext/nomali/tests | |
parent | a0cbf5541133e58968919991635797babaad2a18 (diff) | |
download | gem5-c2740578404b4e46d198de70af1cfd554033d99f.tar.xz |
ext: Add the NoMali GPU no-simulation library
Add revision 9adf9d6e2d889a483a92136c96eb8a434d360561 of NoMali-model
from https://github.com/ARM-software/nomali-model. This library
implements the register interface of the Mali T6xx/T7xx series GPUs,
but doesn't do any rendering. It can be used to hide the effects of
software rendering.
Diffstat (limited to 'ext/nomali/tests')
-rw-r--r-- | ext/nomali/tests/Rules.mk | 44 | ||||
-rw-r--r-- | ext/nomali/tests/nomali_test0.c | 53 | ||||
-rw-r--r-- | ext/nomali/tests/nomali_test_helpers.h | 46 | ||||
-rw-r--r-- | ext/nomali/tests/nomali_test_ints.c | 127 | ||||
-rw-r--r-- | ext/nomali/tests/test_helpers.c | 147 | ||||
-rw-r--r-- | ext/nomali/tests/test_helpers.h | 57 |
6 files changed, 474 insertions, 0 deletions
diff --git a/ext/nomali/tests/Rules.mk b/ext/nomali/tests/Rules.mk new file mode 100644 index 000000000..492a326f2 --- /dev/null +++ b/ext/nomali/tests/Rules.mk @@ -0,0 +1,44 @@ +# +# Copyright (c) 2014-2015 ARM Limited +# All rights reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Authors: Andreas Sandberg + +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(dir) + +HELPER_OBJS := $(addprefix $(d)/, \ + test_helpers.o \ + ) + +TESTS := $(addprefix $(d)/nomali_, \ + test0 \ + test_ints \ + ) + +OBJS := $(HELPER_OBJS) $(addsuffix .o, $(TESTS)) + +ALL_TESTS := $(ALL_TESTS) $(TESTS) +DEPS := $(DEPS) $(OBJS:.o=.d) +CLEAN := $(CLEAN) $(OBJS) $(TESTS) + +include Rules.app.mk + +$(d)/nomali_%: $(d)/nomali_%.o $(d)/test_helpers.o libnomali.so + $(CXX) $(LDFLAGS) -Wl,-rpath -Wl,"$(CURDIR)" -o $@ $^ + +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) diff --git a/ext/nomali/tests/nomali_test0.c b/ext/nomali/tests/nomali_test0.c new file mode 100644 index 000000000..7ae82252c --- /dev/null +++ b/ext/nomali/tests/nomali_test0.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014-2015 ARM Limited + * All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Andreas Sandberg + */ + +#include <libnomali/nomali.h> +#include <inttypes.h> + +#include "nomali_test_helpers.h" +#include "../lib/mali_midg_regmap.h" + +int +main(int argc, char **argv) +{ + const nomali_config_t cfg = { + .type = NOMALI_GPU_T60X, + .ver_maj = 0, + .ver_min = 1, + .ver_status = 0, + }; + nomali_handle_t h; + nomali_error_t error = NOMALI_E_OK; + uint32_t value; + + E_NOMALI_TEST("nomali_create", nomali_create(&h, &cfg)); + if (error != NOMALI_E_OK) + test_bail("Failed to create NoMail instance!"); + + E_NOMALI_TEST("reg_read(GPU_ID)", + nomali_reg_read(h, &value, GPU_CONTROL_REG(GPU_ID))); + if (value != ((GPU_ID_PI_T60X << 16) | 0x10)) { + test_fail("GPU_ID"); + } else + test_ok("GPU_ID"); + + E_NOMALI_TEST("nomali_destroy", nomali_destroy(h)); + + return 0; +} diff --git a/ext/nomali/tests/nomali_test_helpers.h b/ext/nomali/tests/nomali_test_helpers.h new file mode 100644 index 000000000..9de491a2a --- /dev/null +++ b/ext/nomali/tests/nomali_test_helpers.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014-2015 ARM Limited + * All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Andreas Sandberg + */ + +#ifndef _TESTS_NOMALI_TEST_HELPERS_H +#define _TESTS_NOMALI_TEST_HELPERS_H + +#include <libnomali/nomali.h> +#include "test_helpers.h" + +#define E_NOMALI_BAIL(c) \ + do { \ + if ((error = (c)) != NOMALI_E_OK) { \ + test_bail(# c " failed: %s (%i)", \ + nomali_errstr(error), error); \ + } \ + } while (0) + +#define E_NOMALI_TEST(t, c) \ + do { \ + if ((error = (c)) != NOMALI_E_OK) { \ + test_diag(# c " failed: %s (%i)", \ + nomali_errstr(error), error); \ + test_fail(t); \ + } else { \ + test_ok(t); \ + } \ + } while (0) + + +#endif /* _TESTS_NOMALI_TEST_HELPERS_H */ diff --git a/ext/nomali/tests/nomali_test_ints.c b/ext/nomali/tests/nomali_test_ints.c new file mode 100644 index 000000000..54a7083ab --- /dev/null +++ b/ext/nomali/tests/nomali_test_ints.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2014-2015 ARM Limited + * All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Andreas Sandberg + */ + +#include <libnomali/nomali.h> +#include <inttypes.h> + +#include "nomali_test_helpers.h" +#include "../lib/mali_midg_regmap.h" + +static void +on_int(nomali_handle_t h, void *usr, nomali_int_t intno, int set) +{ + test_diag("on_int: intno: %i, set: %i", intno, set); + *(int*)usr = !!set; +} + +static void +test_gpu_int(nomali_handle_t h) +{ + nomali_error_t error = NOMALI_E_OK; + int int_triggered = 0; + nomali_callback_t int_callback = { + .type = NOMALI_CALLBACK_INT, + .usr = &int_triggered, + .func.interrupt = on_int, + }; + + nomali_callback_t int_null_callback = { + .type = NOMALI_CALLBACK_INT, + .usr = NULL, + .func.interrupt = NULL, + }; + + /* + * Raise an interrupt without callbacks + */ + E_NOMALI_BAIL(nomali_reg_write(h, + GPU_CONTROL_REG(GPU_IRQ_CLEAR), + GPU_IRQ_REG_ALL)); + + E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_MASK), + GPU_FAULT)); + + E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), + GPU_FAULT)); + + E_NOMALI_BAIL(nomali_reg_write(h, + GPU_CONTROL_REG(GPU_IRQ_CLEAR), + GPU_IRQ_REG_ALL)); + + /* + * Register callbacks and raise interrupt again. + */ + E_NOMALI_BAIL(nomali_set_callback(h, &int_callback)); + if (int_triggered != 0) { + test_diag("Got spurious interrupt\n"); + test_fail("gpu_int"); + } + + E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), + GPU_FAULT)); + if (int_triggered == 1) { + test_ok("gpu_int"); + } else { + test_fail("gpu_int"); + } + int_triggered = 0; + + + /* + * Register mask interrupts and raise interrupt again. + */ + E_NOMALI_BAIL(nomali_reg_write(h, + GPU_CONTROL_REG(GPU_IRQ_CLEAR), + GPU_IRQ_REG_ALL)); + E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_MASK), + 0)); + E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), + GPU_FAULT)); + if (int_triggered == 0) { + test_ok("gpu_int_masked"); + } else { + test_fail("gpu_int_maked"); + } + E_NOMALI_BAIL(nomali_reg_write(h, + GPU_CONTROL_REG(GPU_IRQ_CLEAR), + GPU_IRQ_REG_ALL)); + E_NOMALI_BAIL(nomali_set_callback(h, &int_null_callback)); +} + +int +main(int argc, char **argv) +{ + const nomali_config_t cfg = { + .type = NOMALI_GPU_T60X, + .ver_maj = 0, + .ver_min = 1, + .ver_status = 0, + }; + + nomali_handle_t h; + nomali_error_t error = NOMALI_E_OK; + + E_NOMALI_BAIL(nomali_create(&h, &cfg)); + + test_gpu_int(h); + + E_NOMALI_BAIL(nomali_destroy(h)); + + return 0; +} diff --git a/ext/nomali/tests/test_helpers.c b/ext/nomali/tests/test_helpers.c new file mode 100644 index 000000000..dad6d4ad1 --- /dev/null +++ b/ext/nomali/tests/test_helpers.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2013 Andreas Sandberg + * All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Andreas Sandberg + */ + +#include "test_helpers.h" + +#include <assert.h> +#include <stdarg.h> +#include <stdlib.h> + +unsigned test_current = 0; +unsigned test_count = 0; +unsigned test_fail_count = 0; + +void +test_init(unsigned no_tests) +{ + assert(test_count == 0 && test_current == 0); + + test_count = no_tests; + test_current = 1; + test_fail_count = 0; + + printf("1..%u\n", no_tests); +} + +void +test_exit() +{ + if (test_fail_count) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); +} + +void +test_bail(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + printf("Bail out! "); + vprintf(fmt, ap); + printf("\n"); + + va_end(ap); + + exit(EXIT_FAILURE); +} + +void +test_diag(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + printf("# "); + vprintf(fmt, ap); + printf("\n"); + + va_end(ap); +} + +static void +test_vstatus(const char *status, const char *test, + const char *directive, + const char *fmt_why, va_list ap) +{ + printf("%s %i", status, test_current); + + if (test && test[0] != '\0') + printf(" - %s", test); + + if (directive && directive[0] != '\0') { + printf(" # %s ", directive); + if (fmt_why && fmt_why[0] != '\0') + vprintf(fmt_why, ap); + } + printf("\n"); + + ++test_current; +} + +static void __attribute__((format (printf, 4, 5))) +test_status(const char *status, const char *test, + const char *directive, + const char *fmt_why, ...) +{ + va_list ap; + va_start(ap, fmt_why); + + test_vstatus(status, test, directive, fmt_why, ap); + + va_end(ap); +} + +void +test_ok(const char *test) +{ + test_status("ok", test, NULL, NULL); +} + +void +test_fail(const char *test) +{ + test_status("not ok", test, NULL, NULL); + ++test_fail_count; +} + +void +test_skip(const char *test, const char *fmt_why, ...) +{ + va_list ap; + va_start(ap, fmt_why); + + test_vstatus("ok", test, "SKIP", fmt_why, ap); + + va_end(ap); +} + +void +test_todo(const char *test, const char *fmt_why, ...) +{ + va_list ap; + va_start(ap, fmt_why); + + test_vstatus("not ok", test, "TODO", fmt_why, ap); + + va_end(ap); + + ++test_fail_count; +} diff --git a/ext/nomali/tests/test_helpers.h b/ext/nomali/tests/test_helpers.h new file mode 100644 index 000000000..68bea288b --- /dev/null +++ b/ext/nomali/tests/test_helpers.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 Andreas Sandberg + * All rights reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Andreas Sandberg + */ + +#ifndef _TEST_HELPERS +#define _TEST_HELPERS 1 + +#include <stdio.h> + +#ifdef __cplusplus +#extern "C" { +#endif + +extern unsigned test_current; +extern unsigned test_count; +extern unsigned test_fail_count; + +void test_init(unsigned no_tests); +void test_exit() + __attribute__((noreturn)); + +void test_bail(const char *fmt, ...) + __attribute__((format (printf, 1, 2), noreturn)); + +void test_diag(const char *fmt, ...) + __attribute__((format (printf, 1, 2))); + +void test_ok(const char *test); + +void test_fail(const char *test); + +void test_skip(const char *test, const char *fmt_why, ...) + __attribute__((format (printf, 2, 3))); + +void test_todo(const char *test, const char *fmt_why, ...) + __attribute__((format (printf, 2, 3))); + +#ifdef __cplusplus +} +#endif + +#endif |