From: Bobby R. Bruce Date: Thu, 20 Aug 2020 20:43:40 +0000 (-0700) Subject: tests: Removed test-progs/pthread X-Git-Tag: v20.1.0.0~140 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=29409425e951970450e1ffd4c0b8f7cfc8ddb0ee;p=gem5.git tests: Removed test-progs/pthread The Pthread source is now found in gem5-resources: https://gem5.googlesource.com/public/gem5-resources/+/refs/heads/master/src/pthreads The pre-compiled binaries are pulled from dist.gem5.org. There is no reason to keep these here. They are therefore being removed. Change-Id: Id07dc72c62d19920fb304eea505deaa9ebc5599f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33141 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- diff --git a/tests/test-progs/pthread/Makefile.aarch32 b/tests/test-progs/pthread/Makefile.aarch32 deleted file mode 100644 index 1acb097d1..000000000 --- a/tests/test-progs/pthread/Makefile.aarch32 +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2019 ARM Limited -# All rights reserved. -# -# The license below extends only to copyright in the software and shall -# not be construed as granting a license to any other intellectual -# property including but not limited to intellectual property relating -# to a hardware implementation of the functionality of the software -# licensed hereunder. You may use the software subject to the license -# terms below provided that you ensure that this notice is replicated -# unmodified and in its entirety in all distributions of the software, -# modified or unmodified, in source code or in binary form. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CROSS_COMPILE = arm-linux-gnueabihf- -BIN_DIR = bin.aarch32 - --include Makefile.common diff --git a/tests/test-progs/pthread/Makefile.aarch64 b/tests/test-progs/pthread/Makefile.aarch64 deleted file mode 100644 index da308202a..000000000 --- a/tests/test-progs/pthread/Makefile.aarch64 +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2019 ARM Limited -# All rights reserved. -# -# The license below extends only to copyright in the software and shall -# not be construed as granting a license to any other intellectual -# property including but not limited to intellectual property relating -# to a hardware implementation of the functionality of the software -# licensed hereunder. You may use the software subject to the license -# terms below provided that you ensure that this notice is replicated -# unmodified and in its entirety in all distributions of the software, -# modified or unmodified, in source code or in binary form. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CROSS_COMPILE = aarch64-linux-gnu- -BIN_DIR = bin.aarch64 - --include Makefile.common diff --git a/tests/test-progs/pthread/Makefile.common b/tests/test-progs/pthread/Makefile.common deleted file mode 100644 index f5957a98e..000000000 --- a/tests/test-progs/pthread/Makefile.common +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2019 ARM Limited -# All rights reserved. -# -# The license below extends only to copyright in the software and shall -# not be construed as granting a license to any other intellectual -# property including but not limited to intellectual property relating -# to a hardware implementation of the functionality of the software -# licensed hereunder. You may use the software subject to the license -# terms below provided that you ensure that this notice is replicated -# unmodified and in its entirety in all distributions of the software, -# modified or unmodified, in source code or in binary form. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CC := $(CROSS_COMPILE)$(CC) -CXX := $(CROSS_COMPILE)$(CXX) -LD := $(CXX) -CCFLAGS ?= -CXXFLAGS ?= -g -O3 -static -std=c++11 -LDFLAGS ?= -pthread - -BIN_DIR ?= ./bin - -TESTS = test_pthread_create_seq \ - test_pthread_create_para \ - test_pthread_mutex \ - test_atomic \ - test_pthread_cond \ - test_std_thread \ - test_std_mutex \ - test_std_condition_variable - -all: $(addprefix $(BIN_DIR)/,$(TESTS)) - -$(BIN_DIR)/%: src/%.cpp - @mkdir -p $(BIN_DIR) - $(CXX) -o $@ $(CCFLAGS) $(CXXFLAGS) $(LDFLAGS) $^ - -clean: - $(RM) $(BIN_DIR)/* - -.PHONY: all clean - diff --git a/tests/test-progs/pthread/Makefile.riscv b/tests/test-progs/pthread/Makefile.riscv deleted file mode 100644 index ea486a74d..000000000 --- a/tests/test-progs/pthread/Makefile.riscv +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2019 ARM Limited -# All rights reserved. -# -# The license below extends only to copyright in the software and shall -# not be construed as granting a license to any other intellectual -# property including but not limited to intellectual property relating -# to a hardware implementation of the functionality of the software -# licensed hereunder. You may use the software subject to the license -# terms below provided that you ensure that this notice is replicated -# unmodified and in its entirety in all distributions of the software, -# modified or unmodified, in source code or in binary form. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CROSS_COMPILE = riscv64-unknown-linux-gnu- -BIN_DIR = bin.riscv64 - --include Makefile.common diff --git a/tests/test-progs/pthread/Makefile.x86 b/tests/test-progs/pthread/Makefile.x86 deleted file mode 100644 index 90013cd83..000000000 --- a/tests/test-progs/pthread/Makefile.x86 +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2019 ARM Limited -# All rights reserved. -# -# The license below extends only to copyright in the software and shall -# not be construed as granting a license to any other intellectual -# property including but not limited to intellectual property relating -# to a hardware implementation of the functionality of the software -# licensed hereunder. You may use the software subject to the license -# terms below provided that you ensure that this notice is replicated -# unmodified and in its entirety in all distributions of the software, -# modified or unmodified, in source code or in binary form. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer; -# redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution; -# neither the name of the copyright holders nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -CROSS_COMPILE = -BIN_DIR = bin.x86 - --include Makefile.common diff --git a/tests/test-progs/pthread/src/test_atomic.cpp b/tests/test-progs/pthread/src/test_atomic.cpp deleted file mode 100644 index 68c94e456..000000000 --- a/tests/test-progs/pthread/src/test_atomic.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include -#include - -//------------------------------------------------------------------------ -// Create n threads, run them in parallel and wait for them in the master -// thread. -// Each child thread increments a shared variable m times atomically -//------------------------------------------------------------------------ - -#define MAX_N_WORKER_THREADS 10 - -typedef struct -{ - int nsteps; - std::atomic* shared_var; -} ThreadArg; - -void* func( void* args ) -{ - ThreadArg* my_args = ( ThreadArg* ) args; - - int nsteps = my_args->nsteps; - std::atomic* shared_var = my_args->shared_var; - - for ( int i = 0; i < nsteps; ++i ) { - std::atomic_fetch_add(shared_var, 1); - } - - return nullptr; -} - -int main( int argc, const char* argv[] ) -{ - int n_worker_threads = 0; - - // allocate all threads - pthread_t* threads = new pthread_t[MAX_N_WORKER_THREADS]; - - // variable shared among all threads - std::atomic shared_var(0); - - // number of steps each thread increments the shared_var - int nsteps = 1000; - - // set up threads' arguments - ThreadArg* t_args = new ThreadArg[MAX_N_WORKER_THREADS]; - - int ret = 0; - for ( size_t tid = 0; tid < MAX_N_WORKER_THREADS; tid++ ){ - t_args[tid].nsteps = nsteps; - t_args[tid].shared_var = &shared_var; - - // spawn thread - ret = pthread_create( threads + tid, nullptr, func, &t_args[tid] ); - - if (ret != 0) { - break; - } - - n_worker_threads++; - } - - // sync up all threads - for ( int tid = 0; tid < n_worker_threads; ++tid ) { - pthread_join( threads[tid], nullptr ); - } - - // clean up - delete[] threads; - delete[] t_args; - - // verify - if ( shared_var != n_worker_threads * nsteps || n_worker_threads < 1) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_pthread_cond.cpp b/tests/test-progs/pthread/src/test_pthread_cond.cpp deleted file mode 100644 index 5552f7853..000000000 --- a/tests/test-progs/pthread/src/test_pthread_cond.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Author: Moyang Wang - */ - -#include - -#include -#include -#include -#include - -//------------------------------------------------------------------------ -// Test pthread_cond -//------------------------------------------------------------------------ -// The master thread creates N threads, each of which waits on a -// condition variable of a signal to start. The master thread then set -// the signal and notifies all other threads to begin. - -#define MAX_N_WORKER_THREADS 10 - -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cv = PTHREAD_COND_INITIALIZER; - -bool ready = false; - -void* print_id( void* arg_vptr ) -{ - pthread_mutex_lock( &mutex ); - long id = (long)arg_vptr; - - while (!ready) { - pthread_cond_wait( &cv, &mutex ); - } - // ... - std::cout << "thread " << id << '\n'; - - pthread_mutex_unlock( &mutex ); - - return nullptr; -} - -void go() -{ - pthread_mutex_lock( &mutex ); - ready = true; - pthread_cond_broadcast( &cv ); - pthread_mutex_unlock( &mutex ); -} - -int main( int argc, char* argv[] ) -{ - size_t n_worker_threads = 0; - - std::vector< pthread_t > threads( MAX_N_WORKER_THREADS ); - - int ret = 0; - for ( size_t i = 0; i < MAX_N_WORKER_THREADS; i++ ){ - ret = pthread_create( &threads[i], nullptr, print_id, (void*)i ); - if (ret != 0) { - break; - } - n_worker_threads++; - } - - std::cout << n_worker_threads << " threads ready to race...\n"; - - go(); - - for ( size_t i = 1; i < n_worker_threads; i++ ) { - pthread_join( threads[i], nullptr ); - } - - if (n_worker_threads < 1) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_pthread_create_para.cpp b/tests/test-progs/pthread/src/test_pthread_create_para.cpp deleted file mode 100644 index 1b10c9f89..000000000 --- a/tests/test-progs/pthread/src/test_pthread_create_para.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include - -//------------------------------------------------------------------------ -// Create n threads, run them in parallel and wait for them in the master -// thread. -// Each child thread writes its thread id to an output array -//------------------------------------------------------------------------ - -#define MAX_N_WORKER_THREADS 10 - -typedef struct -{ - int tid; - int* output; -} ThreadArg; - -void* func( void* args ) -{ - ThreadArg* my_args = ( ThreadArg* ) args; - - // write tid to this thread's output - (*my_args->output) = my_args->tid; - - return nullptr; -} - -int main( int argc, const char* argv[] ) -{ - int n_worker_threads = 0; - - // allocate all threads - pthread_t* threads = new pthread_t[MAX_N_WORKER_THREADS]; - ThreadArg* t_args = new ThreadArg[MAX_N_WORKER_THREADS]; - - // create an output array for all threads - int* outputs = new int[MAX_N_WORKER_THREADS]; - int ret; - - // try to spawn as many worker threads as possible - for ( int tid = 0; tid < MAX_N_WORKER_THREADS; ++tid ) { - - // set up thread args - t_args[tid].tid = tid; - t_args[tid].output = outputs + tid; - - // spawn thread - ret = pthread_create( threads + tid, nullptr, func, &t_args[tid] ); - if (ret != 0) { - break; - } - - n_worker_threads++; - } - - // sync up all threads - for ( int tid = 0; tid < n_worker_threads; ++tid ) { - pthread_join( threads[tid], nullptr ); - } - - // verify - bool passed = true; - for ( int i = 0; i < n_worker_threads; ++i ) { - if ( outputs[i] != i ) { - passed = false; - } - } - - // clean up - delete[] threads; - delete[] t_args; - delete[] outputs; - - // failed if outputs are not correct or no worker thread was spawned - if (!passed || n_worker_threads < 1) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_pthread_create_seq.cpp b/tests/test-progs/pthread/src/test_pthread_create_seq.cpp deleted file mode 100644 index 2a5a5716c..000000000 --- a/tests/test-progs/pthread/src/test_pthread_create_seq.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include - -//------------------------------------------------------------------------ -// Create n threads and run them one after another -// Each child thread writes its thread id to an output array -//------------------------------------------------------------------------ - -#define MAX_N_WORKER_THREADS 10 - -typedef struct -{ - int tid; - int* output; -} ThreadArg; - -void* func( void* args ) -{ - ThreadArg* my_args = ( ThreadArg* ) args; - - // write tid to this thread's output - (*my_args->output) = my_args->tid; - - return nullptr; -} - -int main( int argc, const char* argv[] ) -{ - int n_worker_threads = 0; - - // allocate all threads - pthread_t* threads = new pthread_t[MAX_N_WORKER_THREADS]; - ThreadArg* t_args = new ThreadArg[MAX_N_WORKER_THREADS]; - - // create an output array for all threads - int* outputs = new int[MAX_N_WORKER_THREADS]; - int ret; - - // try to spawn as many worker threads as possible - for ( int tid = 0; tid < MAX_N_WORKER_THREADS; ++tid ) { - - // set up thread args - t_args[tid].tid = tid; - t_args[tid].output = outputs + tid; - - // spawn thread - ret = pthread_create( threads + tid, nullptr, func, &t_args[tid] ); - if (ret != 0 ) { - break; - } - - n_worker_threads++; - - // wait for the thread to join before moving on - pthread_join( threads[tid], nullptr ); - } - - // verify - bool passed = true; - for ( int i = 0; i < n_worker_threads; ++i ) { - if ( outputs[i] != i ) { - passed = false; - break; - } - } - - // clean up - delete[] threads; - delete[] t_args; - delete[] outputs; - - // failed if outputs are not correct or no worker thread was spawned - if (!passed || n_worker_threads < 1) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_pthread_mutex.cpp b/tests/test-progs/pthread/src/test_pthread_mutex.cpp deleted file mode 100644 index 313539b6d..000000000 --- a/tests/test-progs/pthread/src/test_pthread_mutex.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include -#include - -//------------------------------------------------------------------------ -// Create n threads, run them in parallel and wait for them in the master -// thread. -// Each child thread increments a shared variable m times -//------------------------------------------------------------------------ - -#define MAX_N_WORKER_THREADS 10 - -typedef struct -{ - int nsteps; - int* shared_var; - pthread_mutex_t* lock; -} ThreadArg; - -void* func( void* args ) -{ - ThreadArg* my_args = ( ThreadArg* ) args; - - int nsteps = my_args->nsteps; - int* shared_var = my_args->shared_var; - pthread_mutex_t* lock = my_args->lock; - - for ( int i = 0; i < nsteps; ++i ) { - // acquire the lock - pthread_mutex_lock(lock); - - // increment the shared_var - (*shared_var)++; - - // release the lock - pthread_mutex_unlock(lock); - } - - return nullptr; -} - -int main( int argc, const char* argv[] ) -{ - int n_worker_threads = 0; - - // allocate all threads - pthread_t* threads = new pthread_t[MAX_N_WORKER_THREADS]; - ThreadArg* t_args = new ThreadArg[MAX_N_WORKER_THREADS]; - - // variable shared among all threads - int shared_var = 0; - - // number of steps each thread increments the shared_var - int nsteps = 10000; - - // create a shared lock - pthread_mutex_t lock; - pthread_mutex_init(&lock, NULL); - - int ret; - - // try to spawn as many worker threads as possible - for ( int tid = 0; tid < MAX_N_WORKER_THREADS; ++tid ) { - t_args[tid].nsteps = nsteps; - t_args[tid].shared_var = &shared_var; - t_args[tid].lock = &lock; - - // spawn thread - ret = pthread_create( threads + tid, nullptr, func, &t_args[tid] ); - - if (ret != 0) - break; - - n_worker_threads++; - } - - // sync up all threads - for ( int tid = 0; tid < n_worker_threads; ++tid ) { - pthread_join( threads[tid], nullptr ); - } - - // verify - bool passed = true; - if ( shared_var != n_worker_threads * nsteps ) - passed = false; - - // clean up - delete[] threads; - delete[] t_args; - - if (!passed || n_worker_threads < 1) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_std_condition_variable.cpp b/tests/test-progs/pthread/src/test_std_condition_variable.cpp deleted file mode 100644 index b3d162dad..000000000 --- a/tests/test-progs/pthread/src/test_std_condition_variable.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -//------------------------------------------------------------------------ -// Test std::condition_variable -//------------------------------------------------------------------------ -// The master thread creates N threads, each of which waits on a -// condition variable of a signal to start. The master thread then set -// the signal and notifies all other threads to begin. - -#define MAX_N_WORKER_THREADS 10 - -std::mutex mtx; -std::condition_variable cv; -bool ready = false; - -void print_id( size_t id ) -{ - std::unique_lock lck(mtx); - while (!ready) - cv.wait(lck); - // ... - std::cout << "thread " << id << '\n'; -} - -void go() -{ - std::unique_lock lck(mtx); - ready = true; - cv.notify_all(); -} - -int main( int argc, char* argv[] ) -{ - size_t n_worker_threads = 0; - - std::vector< std::thread > threads; - - for ( size_t i = 0; i < MAX_N_WORKER_THREADS; i++ ) { - try { - threads.push_back( std::thread( print_id, i ) ); - } catch ( const std::system_error& err ) { - break; - } - n_worker_threads++; - } - - std::cout << n_worker_threads << " threads ready to race...\n"; - go(); // go! - - for (int i = 0; i < n_worker_threads; ++i) { - threads[i].join(); - } - - // if there is no timeout (i.e., threads are all waken up properly, this - // test always succeeds) - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_std_mutex.cpp b/tests/test-progs/pthread/src/test_std_mutex.cpp deleted file mode 100644 index e81f60ff6..000000000 --- a/tests/test-progs/pthread/src/test_std_mutex.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -//------------------------------------------------------------------------ -// Create n threads, run them in parallel and wait for them in the master -// thread. -// Each child thread increments a shared variable m times -//------------------------------------------------------------------------ - -#define MAX_N_WORKER_THREADS 10 - -int main( int argc, const char* argv[] ) -{ - int n_worker_threads = 0; - - // allocate all threads - std::vector< std::thread > threads; - - // mutex to protect the shared variable - std::mutex my_mutex; - - // variable shared among all threads - int shared_var = 0; - - // number of steps each thread increments the shared_var - int nsteps = 1000; - - for ( int tid = 0; tid < MAX_N_WORKER_THREADS; ++tid ) { - try { - threads.push_back( std::thread( [&] { - std::lock_guard guard(my_mutex); - for ( int i = 0; i < nsteps; ++i ) - shared_var++; - } ) ); - } catch ( const std::system_error& err ) { - break; - } - n_worker_threads++; - } - - // sync up all threads - for (int i = 0; i < n_worker_threads; ++i) { - threads[i].join(); - } - - // verify - if ( shared_var != n_worker_threads * nsteps || n_worker_threads < 1) { - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/tests/test-progs/pthread/src/test_std_thread.cpp b/tests/test-progs/pthread/src/test_std_thread.cpp deleted file mode 100644 index 6634d9085..000000000 --- a/tests/test-progs/pthread/src/test_std_thread.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018, Cornell University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * Neither the name of Cornell University nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -//------------------------------------------------------------------------ -// Test std::thread -//------------------------------------------------------------------------ -// Create n threads, run them in parallel and wait for them in the master -// thread. -// Each child thread writes its thread id to an output array - -#define MAX_N_WORKER_THREADS 10 - -int main( int argc, char* argv[] ) -{ - int n_worker_threads = 0; - - std::vector< std::thread > threads; - std::vector outputs( MAX_N_WORKER_THREADS, 0 ); - - for ( int tid = 0; tid < MAX_N_WORKER_THREADS; ++tid ) { - try { - threads.push_back( std::thread( [&] (size_t thread_id ) { - std::cout << "Hello from thread " << thread_id - << std::endl; - outputs[thread_id] = thread_id; - }, tid ) ); - } catch ( const std::system_error& err ) { - break; - } - n_worker_threads++; - } - - std::cout << "Hello from master thread" << std::endl; - - // sync up all threads - for (int i = 0; i < n_worker_threads; ++i) { - threads[i].join(); - } - - if (n_worker_threads < 1) { - return EXIT_FAILURE; - } - - for ( int i = 0; i < n_worker_threads; ++i ) { - if ( outputs[i] != i ) { - return EXIT_FAILURE; - } - } - - return EXIT_SUCCESS; -}