diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index bd66a5744..14b1bfd9e 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -38,6 +38,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/posix/bitops NV_REPOSITORY_COMPONENTS += userspace/units/posix/env NV_REPOSITORY_COMPONENTS += userspace/units/posix/mockio NV_REPOSITORY_COMPONENTS += userspace/units/posix/fault-injection +NV_REPOSITORY_COMPONENTS += userspace/units/posix/bug NV_REPOSITORY_COMPONENTS += userspace/units/interface/bsearch NV_REPOSITORY_COMPONENTS += userspace/units/interface/lock NV_REPOSITORY_COMPONENTS += userspace/units/interface/atomic diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index f6ed58948..20b3dca6a 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -46,6 +46,7 @@ UNITS := \ $(UNIT_SRC)/posix/bitops \ $(UNIT_SRC)/posix/mockio \ $(UNIT_SRC)/posix/fault-injection \ + $(UNIT_SRC)/posix/bug \ $(UNIT_SRC)/pramin \ $(UNIT_SRC)/fuse \ $(UNIT_SRC)/interface/bsearch \ diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 113ec733c..720da6524 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -1387,6 +1387,11 @@ "test_level": 0, "unit": "posix_bitops" }, + { + "test": "expect_bug", + "test_level": 0, + "unit": "posix_bug" + }, { "test": "endianness", "test_level": 0, @@ -1412,11 +1417,6 @@ "test_level": 0, "unit": "posix_env" }, - { - "test": "readl_impl", - "test_level": 0, - "unit": "posix_mockio" - }, { "test": "bar1_readl", "test_level": 0, @@ -1432,6 +1432,11 @@ "test_level": 0, "unit": "posix_mockio" }, + { + "test": "readl_impl", + "test_level": 0, + "unit": "posix_mockio" + }, { "test": "register_io_callbacks", "test_level": 0, diff --git a/userspace/units/posix/bug/Makefile b/userspace/units/posix/bug/Makefile new file mode 100644 index 000000000..478fbc506 --- /dev/null +++ b/userspace/units/posix/bug/Makefile @@ -0,0 +1,26 @@ +# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +.SUFFIXES: + +OBJS = posix-bug.o +MODULE = posix-bug + +include ../../Makefile.units diff --git a/userspace/units/posix/bug/Makefile.interface.tmk b/userspace/units/posix/bug/Makefile.interface.tmk new file mode 100644 index 000000000..554c568eb --- /dev/null +++ b/userspace/units/posix/bug/Makefile.interface.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=posix-bug + +include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk + +# Local Variables: +# indent-tabs-mode: t +# tab-width: 8 +# End: +# vi: set tabstop=8 noexpandtab: diff --git a/userspace/units/posix/bug/Makefile.tmk b/userspace/units/posix/bug/Makefile.tmk new file mode 100644 index 000000000..ab211a47f --- /dev/null +++ b/userspace/units/posix/bug/Makefile.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# +# tmake for SW Mobile component makefile +# +############################################################################### + +NVGPU_UNIT_NAME=posix-bug + +include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk + +# Local Variables: +# indent-tabs-mode: t +# tab-width: 8 +# End: +# vi: set tabstop=8 noexpandtab: diff --git a/userspace/units/posix/bug/posix-bug.c b/userspace/units/posix/bug/posix-bug.c new file mode 100644 index 000000000..651005305 --- /dev/null +++ b/userspace/units/posix/bug/posix-bug.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#include +#include +#include + +#include + +/* + * Simple wrapper function to call BUG() or not. It was not strictly necessary + * to wrap the call to BUG() in a function but it better ressembles the way + * EXPECT_BUG is to be used in unit tests. + */ +static void bug_caller(struct unit_module *m, bool call) +{ + if (call == true) { + unit_info(m, "Calling BUG()\n"); + BUG(); + } else { + unit_info(m, "Not calling BUG()\n"); + } +} + +/* + * Test to ensure the EXPECT_BUG construct works as intended by making sure it + * behaves properly when BUG is called or not. + * In the event that EXPECT_BUG is completely broken, the call to BUG() would + * cause the unit to crash and report a failure correctly. + */ +static int test_expect_bug(struct unit_module *m, + struct gk20a *g, void *args) +{ + + /* Make sure calls to BUG() are caught as intended. */ + if (!EXPECT_BUG(bug_caller(m, true))) { + unit_err(m, "BUG() was not called but it was expected.\n"); + return UNIT_FAIL; + } else { + unit_info(m, "BUG() was called as expected\n"); + } + + /* Make sure there are no false positives when BUG is not called. */ + if (!EXPECT_BUG(bug_caller(m, false))) { + unit_info(m, "BUG() was not called as expected.\n"); + } else { + unit_err(m, "BUG() was called but it was not expected.\n"); + return UNIT_FAIL; + } + + return UNIT_SUCCESS; +} + +struct unit_module_test posix_bug_tests[] = { + UNIT_TEST(expect_bug, test_expect_bug, NULL, 0), +}; + +UNIT_MODULE(posix_bug, posix_bug_tests, UNIT_PRIO_POSIX_TEST);