Skip to content

Commit

Permalink
Fix format, remove unneeded test complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRFairhurst committed Nov 1, 2024
1 parent fb3c5e7 commit 20bae20
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 66 deletions.
32 changes: 16 additions & 16 deletions c/misra/test/rules/DIR-5-3/BannedDynamicThreadCreation.expected
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
| test.c:37:3:37:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:36:6:36:34 | make_threads_called_from_main | make_threads_called_from_main |
| test.c:38:3:38:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:36:6:36:34 | make_threads_called_from_main | make_threads_called_from_main |
| test.c:46:3:46:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:45:6:45:51 | make_threads_called_from_func_called_from_main | make_threads_called_from_func_called_from_main |
| test.c:47:3:47:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:45:6:45:51 | make_threads_called_from_func_called_from_main | make_threads_called_from_func_called_from_main |
| test.c:56:3:56:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:57:3:57:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:65:3:65:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:66:3:66:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:74:3:74:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:73:6:73:39 | make_threads_called_from_thrd_func | make_threads_called_from_thrd_func |
| test.c:75:3:75:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:73:6:73:39 | make_threads_called_from_thrd_func | make_threads_called_from_thrd_func |
| test.c:83:3:83:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:82:6:82:59 | make_threads_called_from_func_called_from_pthread_thrd | make_threads_called_from_func_called_from_pthread_thrd |
| test.c:84:3:84:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:82:6:82:59 | make_threads_called_from_func_called_from_pthread_thrd | make_threads_called_from_func_called_from_pthread_thrd |
| test.c:88:3:88:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:87:6:87:47 | make_threads_called_from_main_pthread_thrd | make_threads_called_from_main_pthread_thrd |
| test.c:89:3:89:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:87:6:87:47 | make_threads_called_from_main_pthread_thrd | make_threads_called_from_main_pthread_thrd |
| test.c:93:3:93:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:92:6:92:38 | make_threads_not_called_by_anyone | make_threads_not_called_by_anyone |
| test.c:94:3:94:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:92:6:92:38 | make_threads_not_called_by_anyone | make_threads_not_called_by_anyone |
| test.c:28:3:28:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:27:6:27:34 | make_threads_called_from_main | make_threads_called_from_main |
| test.c:29:3:29:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:27:6:27:34 | make_threads_called_from_main | make_threads_called_from_main |
| test.c:37:3:37:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:36:6:36:51 | make_threads_called_from_func_called_from_main | make_threads_called_from_func_called_from_main |
| test.c:38:3:38:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:36:6:36:51 | make_threads_called_from_func_called_from_main | make_threads_called_from_func_called_from_main |
| test.c:47:3:47:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:48:3:48:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:56:3:56:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:57:3:57:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:65:3:65:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:64:6:64:39 | make_threads_called_from_thrd_func | make_threads_called_from_thrd_func |
| test.c:66:3:66:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:64:6:64:39 | make_threads_called_from_thrd_func | make_threads_called_from_thrd_func |
| test.c:74:3:74:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:73:6:73:59 | make_threads_called_from_func_called_from_pthread_thrd | make_threads_called_from_func_called_from_pthread_thrd |
| test.c:75:3:75:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:73:6:73:59 | make_threads_called_from_func_called_from_pthread_thrd | make_threads_called_from_func_called_from_pthread_thrd |
| test.c:79:3:79:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:78:6:78:47 | make_threads_called_from_main_pthread_thrd | make_threads_called_from_main_pthread_thrd |
| test.c:80:3:80:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:78:6:78:47 | make_threads_called_from_main_pthread_thrd | make_threads_called_from_main_pthread_thrd |
| test.c:84:3:84:13 | call to thrd_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:83:6:83:38 | make_threads_not_called_by_anyone | make_threads_not_called_by_anyone |
| test.c:85:3:85:16 | call to pthread_create | Possible dynamic creation of thread outside initialization in function '$@'. | test.c:83:6:83:38 | make_threads_not_called_by_anyone | make_threads_not_called_by_anyone |
28 changes: 14 additions & 14 deletions c/misra/test/rules/DIR-5-3/ThreadCreatedByThread.expected
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
| test.c:56:3:56:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:57:3:57:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:65:3:65:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:66:3:66:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:74:3:74:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:75:3:75:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:83:3:83:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:83:3:83:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:84:3:84:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:84:3:84:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:88:3:88:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:88:3:88:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:89:3:89:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:7:55:18 | pthread_func | pthread_func |
| test.c:89:3:89:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:64:5:64:13 | thrd_func | thrd_func |
| test.c:47:3:47:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:48:3:48:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:56:3:56:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:57:3:57:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:65:3:65:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:66:3:66:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:74:3:74:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:74:3:74:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:75:3:75:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:75:3:75:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:79:3:79:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:79:3:79:13 | call to thrd_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
| test.c:80:3:80:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:46:7:46:18 | pthread_func | pthread_func |
| test.c:80:3:80:16 | call to pthread_create | Thread creation call reachable from threaded function '$@'. | test.c:55:5:55:13 | thrd_func | thrd_func |
63 changes: 27 additions & 36 deletions c/misra/test/rules/DIR-5-3/test.c
Original file line number Diff line number Diff line change
@@ -1,95 +1,86 @@
#include "threads.h"
#include "pthread.h"
#include "threads.h"

thrd_t g1; // COMPLIANT
thrd_t g1; // COMPLIANT
pthread_t g2; // COMPLIANT
thrd_t g3[10]; // COMPLIANT
pthread_t g4[10]; // COMPLIANT

struct {
thrd_t m1; // COMPLIANT
pthread_t m2; // COMPLIANT
} g7;

void* pthread_func(void* arg);
int thrd_func(void* arg);
void *pthread_func(void *arg);
int thrd_func(void *arg);

void make_threads_called_from_main(void);
void func_called_from_main(void);
void make_threads_called_from_func_called_from_main(void);
void make_threads_called_from_main_pthread_thrd(void);

void main() {
// Main starting top level threads -- ok.
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // COMPLIANT

// Starting thread in pool -- ok.
thrd_create(&g3[0], &thrd_func, NULL); // COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // COMPLIANT

make_threads_called_from_main();
func_called_from_main();
make_threads_called_from_main_pthread_thrd();
}

void make_threads_called_from_main() {
thrd_create(&g3[0], &thrd_func, NULL); // COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // COMPLIANT
}

void func_called_from_main() {
make_threads_called_from_func_called_from_main();
make_threads_called_from_func_called_from_main();
}

void make_threads_called_from_func_called_from_main() {
thrd_create(&g3[0], &thrd_func, NULL); // COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // COMPLIANT
}

void make_threads_called_from_pthread_func(void);
void make_threads_called_from_thrd_func(void);
void func_called_from_pthread_thrd(void);
void make_threads_called_from_func_called_from_pthread_thrd(void);

void* pthread_func(void* arg) {
thrd_create(&g3[0], &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // NON-COMPLIANT
void *pthread_func(void *arg) {
thrd_create(&g1, &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // NON-COMPLIANT

make_threads_called_from_pthread_func();
func_called_from_pthread_thrd();
make_threads_called_from_main_pthread_thrd();
}

int thrd_func(void* arg) {
thrd_create(&g3[0], &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // NON-COMPLIANT
int thrd_func(void *arg) {
thrd_create(&g1, &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // NON-COMPLIANT

make_threads_called_from_thrd_func();
func_called_from_pthread_thrd();
make_threads_called_from_main_pthread_thrd();
}

void make_threads_called_from_thrd_func(void) {
thrd_create(&g3[0], &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // NON-COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // NON-COMPLIANT
}

void func_called_from_pthread_thrd(void) {
make_threads_called_from_func_called_from_pthread_thrd();
make_threads_called_from_func_called_from_pthread_thrd();
}

void make_threads_called_from_func_called_from_pthread_thrd(void) {
thrd_create(&g3[0], &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // NON-COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // NON-COMPLIANT
}

void make_threads_called_from_main_pthread_thrd() {
thrd_create(&g3[0], &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // NON-COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // NON-COMPLIANT
}

void make_threads_not_called_by_anyone() {
thrd_create(&g3[0], &thrd_func, NULL); // COMPLIANT
pthread_create(&g4[0], NULL, &pthread_func, NULL); // COMPLIANT
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // COMPLIANT
}

0 comments on commit 20bae20

Please sign in to comment.