diff --git a/Makefile.umbrella.tmk b/Makefile.umbrella.tmk index 22621085b..970748d04 100644 --- a/Makefile.umbrella.tmk +++ b/Makefile.umbrella.tmk @@ -61,6 +61,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/posix/kmem NV_REPOSITORY_COMPONENTS += userspace/units/posix/rwsem NV_REPOSITORY_COMPONENTS += userspace/units/posix/queue NV_REPOSITORY_COMPONENTS += userspace/units/posix/utils +NV_REPOSITORY_COMPONENTS += userspace/units/posix/circ_buf NV_REPOSITORY_COMPONENTS += userspace/units/interface/bit-utils NV_REPOSITORY_COMPONENTS += userspace/units/interface/bsearch NV_REPOSITORY_COMPONENTS += userspace/units/interface/lock diff --git a/userspace/Makefile.sources b/userspace/Makefile.sources index 6911a00a5..766870d3f 100644 --- a/userspace/Makefile.sources +++ b/userspace/Makefile.sources @@ -57,6 +57,7 @@ UNITS := \ $(UNIT_SRC)/posix/rwsem \ $(UNIT_SRC)/posix/queue \ $(UNIT_SRC)/posix/utils \ + $(UNIT_SRC)/posix/circ_buf \ $(UNIT_SRC)/bus \ $(UNIT_SRC)/pramin \ $(UNIT_SRC)/ptimer \ diff --git a/userspace/SWUTS.h b/userspace/SWUTS.h index fe1035cc4..2131c235d 100644 --- a/userspace/SWUTS.h +++ b/userspace/SWUTS.h @@ -119,6 +119,7 @@ * - @ref SWUTS-posix-ossched * - @ref SWUTS-posix-rwsem * - @ref SWUTS-posix-utils + * - @ref SWUTS-posix-circbuf * - @ref SWUTS-priv_ring * - @ref SWUTS-ptimer * - @ref SWUTS-sdl diff --git a/userspace/SWUTS.sources b/userspace/SWUTS.sources index 83be1c93a..2b51c3bc5 100644 --- a/userspace/SWUTS.sources +++ b/userspace/SWUTS.sources @@ -97,6 +97,7 @@ INPUT += ../../../userspace/units/posix/timers/posix-timers.h INPUT += ../../../userspace/units/posix/os_sched/posix-ossched.h INPUT += ../../../userspace/units/posix/rwsem/posix-rwsem.h INPUT += ../../../userspace/units/posix/utils/posix-utils.h +INPUT += ../../../userspace/units/posix/circ_buf/posix-circbuf.h INPUT += ../../../userspace/units/priv_ring/nvgpu-priv_ring.h INPUT += ../../../userspace/units/ptimer/nvgpu-ptimer.h INPUT += ../../../userspace/units/therm/nvgpu-therm.h diff --git a/userspace/required_tests.json b/userspace/required_tests.json index 3038fcd51..552f3b399 100644 --- a/userspace/required_tests.json +++ b/userspace/required_tests.json @@ -4142,6 +4142,18 @@ "unit": "posix_bug", "test_level": 0 }, + { + "test": "test_circbufcnt", + "case": "circbufcnt", + "unit": "posix_circbuf", + "test_level": 0 + }, + { + "test": "test_circbufspace", + "case": "circbufspace", + "unit": "posix_circbuf", + "test_level": 0 + }, { "test": "test_cond_init_destroy", "case": "init", diff --git a/userspace/units/posix/circ_buf/Makefile b/userspace/units/posix/circ_buf/Makefile new file mode 100644 index 000000000..17dd442d5 --- /dev/null +++ b/userspace/units/posix/circ_buf/Makefile @@ -0,0 +1,26 @@ +# Copyright (c) 2020, 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-circbuf.o +MODULE = posix-circbuf + +include ../../Makefile.units diff --git a/userspace/units/posix/circ_buf/Makefile.interface.tmk b/userspace/units/posix/circ_buf/Makefile.interface.tmk new file mode 100644 index 000000000..b03ffd307 --- /dev/null +++ b/userspace/units/posix/circ_buf/Makefile.interface.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2020, 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-circbuf + +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/circ_buf/Makefile.tmk b/userspace/units/posix/circ_buf/Makefile.tmk new file mode 100644 index 000000000..354217949 --- /dev/null +++ b/userspace/units/posix/circ_buf/Makefile.tmk @@ -0,0 +1,35 @@ +################################### tell Emacs this is a -*- makefile-gmake -*- +# +# Copyright (c) 2020, 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-circbuf + +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/circ_buf/posix-circbuf.c b/userspace/units/posix/circ_buf/posix-circbuf.c new file mode 100644 index 000000000..3cfa6a4bb --- /dev/null +++ b/userspace/units/posix/circ_buf/posix-circbuf.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2020, 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 "posix-circbuf.h" + +#define BUFFER_SIZE 16UL + +int test_circbufcnt(struct unit_module *m, + struct gk20a *g, void *args) +{ + unsigned int i; + unsigned long head, tail, size, ret; + + head = 0; + tail = 0; + size = BUFFER_SIZE; + for (i = 0; i < BUFFER_SIZE; i++) { + head = i; + ret = CIRC_CNT(head, tail, size); + if (ret != i) { + unit_return_fail(m, "CIRC_CNT failed %ld\n", ret); + } + } + + head = BUFFER_SIZE - 1; + for (i = 0; i < BUFFER_SIZE; i++) { + tail = (BUFFER_SIZE - 1) - i; + ret = CIRC_CNT(head, tail, size); + if (ret != i) { + unit_return_fail(m, "CIRC_CNT failed %ld\n", ret); + } + } + + head = BUFFER_SIZE/2; + tail = BUFFER_SIZE/2; + ret = CIRC_CNT(head, tail, size); + if (ret) { + unit_return_fail(m, "CIRC_CNT failed %ld\n", ret); + } + + return UNIT_SUCCESS; +} + +int test_circbufspace(struct unit_module *m, + struct gk20a *g, void *args) +{ + unsigned int i; + unsigned long head, tail, size, ret; + + tail = BUFFER_SIZE; + size = BUFFER_SIZE; + for (i = 0; i < BUFFER_SIZE; i++) { + head = i; + ret = CIRC_SPACE(head, tail, size); + if (ret != ((BUFFER_SIZE - 1) - i)) { + unit_return_fail(m, "CIRC_SPACE failed %ld\n", ret); + } + } + + return UNIT_SUCCESS; +} + +struct unit_module_test posix_circbuf_tests[] = { + UNIT_TEST(circbufcnt, test_circbufcnt, NULL, 0), + UNIT_TEST(circbufspace, test_circbufspace, NULL, 0), +}; + +UNIT_MODULE(posix_circbuf, posix_circbuf_tests, UNIT_PRIO_POSIX_TEST); diff --git a/userspace/units/posix/circ_buf/posix-circbuf.h b/userspace/units/posix/circ_buf/posix-circbuf.h new file mode 100644 index 000000000..f374145fe --- /dev/null +++ b/userspace/units/posix/circ_buf/posix-circbuf.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2020, 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. + */ + +/** + * @addtogroup SWUTS-posix-circbuf + * @{ + * + * Software Unit Test Specification for posix-circbuf + */ + +#ifndef UNIT_POSIX_CIRCBUF_H +#define UNIT_POSIX_CIRCBUF_H + +/** + * Test specification for test_circbufcnt + * + * Description: Test the buffer count implementation. + * + * Test Type: Feature + * + * Targets: CIRC_CNT + * + * Inputs: None + * + * Steps: + * 1) Invoke CIRC_CNT in loop with head assigned with loop index value and + * tail as zero. + * 2) Check if the return value of buffer count is equal to loop index. Else + * return fail. + * 3) Invoke CIRC_CNT in loop with head assigned as maximum index and tail + * decreased according to the loop index value. + * 4) Check if the return value of buffer count is equal to loop index. Else + * return fail. + * 5) Invoke CIRC_CNT with both head and tail assigned with same value. + * 6) Check if the return value is equal to zero, else return fail. + * 7) Return PASS. + * + * Output: + * The test returns PASS if all the invocations of CIRC_CNT returns the + * expected value as buffer count. Otherwise, test returns FAIL. + */ +int test_circbufcnt(struct unit_module *m, struct gk20a *g, void *args); + +/** + * Test specification for test_circbufspace + * + * Description: Test the buffer space check implementation. + * + * Test Type: Feature + * + * Targets: CIRC_SPACE + * + * Inputs: None + * + * Steps: + * 1) Invoke CIRC_SPACE in loop with head assigned as loop index and + * tail as buffer size. + * 2) Check if the return value of buffer space is equal to the maximum + * entries that the buffer can hold minus loop index. Else + * return fail. + * 3) Return PASS. + * + * Output: + * The test returns PASS if all the invocations of CIRC_SPACE returns the + * expected value as available buffer space. Otherwise, test returns FAIL. + */ +int test_circbufspace(struct unit_module *m, struct gk20a *g, void *args); + +#endif /* UNIT_POSIX_CIRCBUF_H */