Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
Issue 319 thread support (#343)
Browse files Browse the repository at this point in the history
* Added pthread sample testcase

* Ada threading testapp

* ada testcases

* pthread testcase

* update pthread worker testcase

* update the licence header
  • Loading branch information
kumarak authored and mike-myers-tob committed Dec 4, 2017
1 parent 63033f4 commit b6d18e1
Show file tree
Hide file tree
Showing 47 changed files with 416 additions and 0 deletions.
Binary file added tests/test_suite/amd64/linux/bc/ada_thread1
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bc/ada_trinary
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bc/ada_worker
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bc/pthread1
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bc/pthread_worker
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bin/ada_thread1
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bin/ada_trinary
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bin/ada_worker
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bin/pthread1
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/bin/pthread_worker
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/cfg/ada_thread1
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/cfg/ada_trinary
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/cfg/ada_worker
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/cfg/pthread1
Binary file not shown.
Binary file added tests/test_suite/amd64/linux/cfg/pthread_worker
Binary file not shown.
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/cppflags/ada_thread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall;
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/cppflags/ada_trinary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall;
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/cppflags/ada_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall;
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/cppflags/pthread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall;-Werror
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/cppflags/pthread_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Wall;-Werror
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/docs/ada_thread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple Ada threading application
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/docs/ada_trinary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A thread implementation in Ada
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/docs/ada_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple producer/consumer implementation in Ada
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/docs/pthread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple pthread support test
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/docs/pthread_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple producer/consumer implementation in pthread.
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/input/ada_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000000
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/input/pthread_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000000
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/linkerflags/ada_thread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-lm -lgnat -lpthread -lgnarl
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/linkerflags/ada_trinary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-lm -lgnat -lpthread -lgnarl
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/linkerflags/ada_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-lm -lgnat -lpthread -lgnarl
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/linkerflags/pthread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-lpthread
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/linkerflags/pthread_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-lpthread
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/stdout/ada_thread1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
111112222200000
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/stdout/ada_trinary
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test Passed 2001000
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/stdout/ada_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Executed 1000000 iterations
7 changes: 7 additions & 0 deletions tests/test_suite/amd64/linux/stdout/pthread1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Create threads
Wait for the threads to complete, and release their resources
foo(), tls data=1 4
bar(), tls data=1 4
foo(), tls data=0 2
bar(), tls data=0 2
Main completed
1 change: 1 addition & 0 deletions tests/test_suite/amd64/linux/stdout/pthread_worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Executed 1000000 iterations
41 changes: 41 additions & 0 deletions tests/test_suite_generator/src/linux/ada_thread1/ada_thread.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--
-- Copyright (c) 2017 Trail of Bits, Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

with Ada.Text_IO;use Ada.Text_IO;

procedure Ada_Thread is
task Write_Zeros;
task Write_Ones;

task body Write_Zeros is
begin
for I in 1..5 loop
Put ('0');
end loop;
end Write_Zeros;

task body Write_Ones is
begin
for I in 1..5 loop
Put ('1');
end loop;
end Write_Ones;

begin
for I in 1..5 loop
Put ('2');
end loop;
end Ada_Thread;
Binary file not shown.
Binary file not shown.
49 changes: 49 additions & 0 deletions tests/test_suite_generator/src/linux/ada_trinary/ada_trinary.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--
-- Copyright (c) 2017 Trail of Bits, Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

with Ada.Text_IO;
use Ada.Text_IO;

procedure Ada_Trinary is
task Task1;
task Task2;

Task_Var1 : Integer := 0;
Task_Var2 : Integer := 0;

task body Task1 is
begin
for I in 1..2000 loop
Task_Var1 := Task_Var1 + I;
-- Put_Line ("Task 1 " & Integer'Image(Task_Var1));
end loop;
end Task1;

task body Task2 is
begin
for I in 1..2000 loop
Task_Var2 := Task_Var2 + I;
-- Put_Line ("Task 2 " & Integer'Image(Task_Var2));
end loop;
end Task2;

begin
loop
delay Duration(0.1);
exit when Task_Var1 = Task_Var2;
end loop;
Put_Line ("Test Passed " & Integer'Image(Task_Var1));
end Ada_Trinary;
Binary file not shown.
53 changes: 53 additions & 0 deletions tests/test_suite_generator/src/linux/ada_worker/ada_worker.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
with Ada.Command_Line;
with Ada.Text_IO;

procedure Ada_Worker is
Iterations : Positive := Positive'Value(Ada.Command_Line.Argument (1));
protected Buffer is
entry Put (X : in Boolean);
entry Get (X : out Boolean);
private
Value : Boolean;
Full : Boolean := False;
end Buffer;

protected body Buffer is
entry Put (X : in Boolean) when not Full is
begin
Value := X;
Full := True;
end Put;
entry Get (X : out Boolean) when Full is
begin
X := Value;
Full := False;
end Get;
end Buffer;


task Ada_Producer;
task Ada_Consumer;

task body Ada_Producer is
begin
for I in 1 .. Iterations - 1 loop
Buffer.Put (False);
end loop;
Buffer.Put (True);
end Ada_Producer;

task body Ada_Consumer is
X : Boolean;
Count : Natural := 0;
begin
loop
Buffer.Get (X);
Count := Count + 1;
exit when X;
end loop;
Ada.Text_IO.Put_Line ("Executed " & Natural'Image (Count) & " iterations");
end Ada_Consumer;

begin
null;
end Ada_Worker;
28 changes: 28 additions & 0 deletions tests/test_suite_generator/src/linux/pthread1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2017 Trail of Bits, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specifi

project(pthread1)
cmake_minimum_required(VERSION 3.2)

set(PROJECT_CXXFLAGS -Wall -Werror)
set(PROJECT_LDFLAGS -lpthread)

set(PROJECT_SOURCEFILES
main.c
)

GenerateTest(${PROJECT_NAME}
SOURCES ${PROJECT_SOURCEFILES}
CXXFLAGS ${PROJECT_CXXFLAGS}
LDFLAGS ${PROJECT_LDFLAGS}
)
77 changes: 77 additions & 0 deletions tests/test_suite_generator/src/linux/pthread1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2017 Trail of Bits, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

__thread int tls_data1;
__thread int tls_data2;

typedef struct {
int data1;
int data2;
} thread_parm_t;

void bar() {
printf("bar(), tls data=%d %d\n", tls_data1, tls_data2);
return;
}

void foo() {
printf("foo(), tls data=%d %d\n", tls_data1, tls_data2);
bar();
}

void *theThread(void *parm)
{
int rc;
thread_parm_t *gData;
gData = (thread_parm_t*)parm;
tls_data1 = gData->data1;
tls_data2 = gData->data2;
foo();
return NULL;
}

int main(int argc, char **argv) {
int rc=0, i;
pthread_t thread[2];
thread_parm_t gData[2];

printf("Create threads\n");
for (i=0; i < 2; i++) {
gData[i].data1 = i;
gData[i].data2 = (i+1)*2;
rc = pthread_create(&thread[i], NULL, theThread, &gData[i]);
if (rc) {
printf("Failed with %d at pthread_create()", rc);
exit(1);
}
}

printf("Wait for the threads to complete, and release their resources\n");
for (i=0; i < 2; i++) {
rc = pthread_join(thread[i], NULL);
if (rc) {
printf("Failed with %d at pthread_join()", rc);
exit(1);
}
}

printf("Main completed\n");
return 0;
}
28 changes: 28 additions & 0 deletions tests/test_suite_generator/src/linux/pthread_worker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2017 Trail of Bits, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specifi

project(pthread1)
cmake_minimum_required(VERSION 3.2)

set(PROJECT_CXXFLAGS -Wall -Werror)
set(PROJECT_LDFLAGS -lpthread)

set(PROJECT_SOURCEFILES
main.cpp
)

GenerateTest(${PROJECT_NAME}
SOURCES ${PROJECT_SOURCEFILES}
CXXFLAGS ${PROJECT_CXXFLAGS}
LDFLAGS ${PROJECT_LDFLAGS}
)
Loading

0 comments on commit b6d18e1

Please sign in to comment.