From e0a72ba70e082eb969a9d9cb11232f77020c8556 Mon Sep 17 00:00:00 2001 From: Dan Walkes Date: Sat, 22 Jan 2022 17:58:53 -0700 Subject: [PATCH 1/2] Remove full test for assignment 4 Full test for assignment 4 is completed through the buildroot repository, this repo is only used for unit testing in assignment 4. --- .github/workflows/github-actions.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index db7808e..94a5373 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -10,12 +10,3 @@ jobs: run : git submodule update --init --recursive - name: Run unit test run: ./unit-test.sh - full-test: - container: cuaesd/aesd-autotest:assignment3 - runs-on: self-hosted - steps: - - uses: actions/checkout@v2 - - name: Checkout submodules - run : git submodule update --init --recursive - - name: Run full test - run: ./full-test.sh From 3a5e8e8588347ccb4ce0fc4ed3f74f907ab9af70 Mon Sep 17 00:00:00 2001 From: Dan Walkes Date: Sat, 21 May 2022 17:52:30 -0600 Subject: [PATCH 2/2] Add threading tets for assignment 4 --- CMakeLists.txt | 7 ++++-- conf/assignment.txt | 2 +- examples/threading/threading.c | 33 ++++++++++++++++++++++++++++ examples/threading/threading.h | 40 ++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 examples/threading/threading.c create mode 100644 examples/threading/threading.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a3d8066..cf2c9a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,14 +4,17 @@ project(aesd-assignments) # At minimum it should include the files in the test/assignmentX directory # Students can also add paths to their own test files using a ../ prefix to # reference this working directory + +set(CMAKE_C_FLAGS "-pthread") + set(AUTOTEST_SOURCES test/assignment1/Test_hello.c test/assignment1/Test_assignment_validate.c - test/assignment3/Test_systemcalls.c + test/assignment4/Test_threading.c ) # A list of all files containing test code that is used for assignment validation set(TESTED_SOURCE ../examples/autotest-validate/autotest-validate.c - ../examples/systemcalls/systemcalls.c + ../examples/threading/threading.c ) add_subdirectory(assignment-autotest) diff --git a/conf/assignment.txt b/conf/assignment.txt index 62cc2d1..9741fbd 100644 --- a/conf/assignment.txt +++ b/conf/assignment.txt @@ -1 +1 @@ -assignment3 +assignment4 diff --git a/examples/threading/threading.c b/examples/threading/threading.c new file mode 100644 index 0000000..c2a6e5d --- /dev/null +++ b/examples/threading/threading.c @@ -0,0 +1,33 @@ +#include "threading.h" +#include +#include +#include + +// Optional: use these functions to add debug or error prints to your application +#define DEBUG_LOG(msg,...) +//#define DEBUG_LOG(msg,...) printf("threading: " msg "\n" , ##__VA_ARGS__) +#define ERROR_LOG(msg,...) printf("threading ERROR: " msg "\n" , ##__VA_ARGS__) + +void* threadfunc(void* thread_param) +{ + + // TODO: wait, obtain mutex, wait, release mutex as described by thread_data structure + // hint: use a cast like the one below to obtain thread arguments from your parameter + //struct thread_data* thread_func_args = (struct thread_data *) thread_param; + return thread_param; +} + + +bool start_thread_obtaining_mutex(pthread_t *thread, pthread_mutex_t *mutex,int wait_to_obtain_ms, int wait_to_release_ms) +{ + /** + * TODO: allocate memory for thread_data, setup mutex and wait arguments, pass thread_data to created thread + * using threadfunc() as entry point. + * + * return true if successful. + * + * See implementation details in threading.h file comment block + */ + return false; +} + diff --git a/examples/threading/threading.h b/examples/threading/threading.h new file mode 100644 index 0000000..fb68f18 --- /dev/null +++ b/examples/threading/threading.h @@ -0,0 +1,40 @@ +#include +#include + +/** + * This structure should be dynamically allocated and passed as + * an argument to your thread using pthread_create. + * It should be returned by your thread so it can be freed by + * the joiner thread. + */ +struct thread_data{ + /* + * TODO: add other values your thread will need to manage + * into this structure, use this structure to communicate + * between the start_thread_obtaining_mutex function and + * your thread implementation. + */ + + /** + * Set to true if the thread completed with success, false + * if an error occurred. + */ + bool thread_complete_success; +}; + + +/** +* Start a thread which sleeps @param wait_to_obtain_ms number of milliseconds, then obtains the +* mutex in @param mutex, then holds for @param wait_to_release_ms milliseconds, then releases. +* The start_thread_obtaining_mutex function should only start the thread and should not block +* for the thread to complete. +* The start_thread_obtaining_mutex function should use dynamic memory allocation for thread_data +* structure passed into the thread. The number of threads active should be limited only by the +* amount of available memory. +* The thread started should return a pointer to the thread_data structure when it exits, which can be used +* to free memory as well as to check thread_complete_success for successful exit. +* If a thread was started succesfully @param thread should be filled with the pthread_create thread ID +* coresponding to the thread which was started. +* @return true if the thread could be started, false if a failure occurred. +*/ +bool start_thread_obtaining_mutex(pthread_t *thread, pthread_mutex_t *mutex,int wait_to_obtain_ms, int wait_to_release_ms);