Skip to content

Commit 1e9dc7e

Browse files
authored
initial gcov integration (#123)
* initial gcov integration * fix sym_print signature * misc * reorg and comment
1 parent 97d4989 commit 1e9dc7e

File tree

6 files changed

+144
-3
lines changed

6 files changed

+144
-3
lines changed

dev-clean/headers/llsc/smt_checker.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class CachedChecker : public Checker {
216216
ABORT("Cannot create the test case file, abort.\n");
217217
}
218218
for (auto [k, v]: *model) {
219-
output << k->name << " == " << v << std::endl;
219+
output << k->name << "=" << v << std::endl;
220220
}
221221
int n = write(out_fd, output.str().c_str(), output.str().size());
222222
close(out_fd);

dev-clean/headers/llsc_client.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
#define LLSC_CLIENT_HEADERS
33

44
#include <stdio.h>
5-
#include "stdint.h"
5+
#include <stdint.h>
66
#include <stddef.h>
7+
#include <stdarg.h>
78
#include <stdbool.h>
89

910
// TODO: support assigning names for symbolic values
1011

1112
/* Construct `byte_size` 8-bitvectors starting at address `addr`.
1213
*/
1314
void make_symbolic(void* addr, size_t byte_size);
15+
void llsc_make_symbolic(void* addr, size_t byte_size, char* name);
1416

1517
/* Construct a single bitvector of size `byte_size`*8 at address `addr`.
1618
*/
@@ -22,7 +24,7 @@ void llsc_assert(bool);
2224
void llsc_assert_eager(bool);
2325

2426
void llsc_assume(bool);
25-
27+
void sym_print(int, ...);
2628
void print_string(const char *message);
2729

2830
/* llsc_range - Construct a symbolic value in the signed interval

dev-clean/scripts/gcov_driver.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import glob
6+
import subprocess
7+
8+
# example
9+
# python3 driver.py ../llsc_gen/ImpCPSLLSC_quickSortTest/tests quicksort.c
10+
11+
if __name__ == "__main__":
12+
tests_folder = sys.argv[1]
13+
src_file = sys.argv[2]
14+
target = src_file.split(".")[0]
15+
cmd = "gcc -fprofile-arcs -ftest-coverage -o {} llsc_client.c {}".format(target, src_file)
16+
print("Compiling: {}".format(cmd))
17+
os.system(cmd)
18+
print("Reading test cases from {}".format(tests_folder))
19+
# TODO: find the metainfo file in test_folder
20+
for test_case in glob.glob(tests_folder+"/*.test"):
21+
print("Testing {}".format(test_case))
22+
env = dict(os.environ)
23+
# TODO: read the test file and create corresponding files, redirect stdin/stdout/stderr
24+
env["LLSC_TEST_FILE"] = test_case
25+
# TODO: synthesize argv
26+
# argv = "..."
27+
subprocess.Popen(["./"+target], env=env)
28+
os.system("gcov -b -c {}-{}".format(target, target))

dev-clean/scripts/llsc_client.c

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <stddef.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
#include <assert.h>
7+
#include <stdbool.h>
8+
9+
#define LLSC_TEST_FILE "LLSC_TEST_FILE"
10+
11+
int32_t is_key(char* key, char* name_prefix, size_t size) {
12+
char* p = strstr(key, name_prefix);
13+
if (p == NULL) return -1;
14+
assert(strlen(name_prefix) < size);
15+
char* n = p + strlen(name_prefix);
16+
int32_t v = strtol(n, (char**)NULL, 10);
17+
assert(v >= 0);
18+
return v;
19+
}
20+
21+
// name can only be alphabet letters, containing no numbers
22+
void make_symbolic(void* addr, size_t byte_size, char* name_prefix) {
23+
const char* path = getenv(LLSC_TEST_FILE);
24+
char* line = NULL;
25+
size_t len = 0;
26+
ssize_t read;
27+
FILE* fp = fopen(path, "r");
28+
if (fp == NULL) {
29+
fprintf(stderr, "Test file %s not exists\n", path);
30+
exit(-1);
31+
}
32+
fprintf(stdout, "Reading test case from %s\n", path);
33+
34+
uint8_t* reified_data = (uint8_t*)malloc(byte_size);
35+
while ((read = getline(&line, &len, fp)) != -1) {
36+
char* value_ptr = strstr(line, "=");
37+
if (value_ptr == NULL) continue;
38+
size_t key_size = value_ptr - line;
39+
line[key_size] = '\0';
40+
//printf("%s, %s", line, value_ptr+1);
41+
int idx = is_key(line, name_prefix, key_size);
42+
if (idx == -1) continue;
43+
assert(idx >= 0 && idx < byte_size);
44+
uint8_t v = (uint8_t) strtol(value_ptr+1, (char **)NULL, 10);
45+
reified_data[idx] = v;
46+
//printf("%s%d -> %d\n", name_prefix, idx, v);
47+
}
48+
memcpy(addr, (void*)reified_data, byte_size);
49+
free(reified_data);
50+
free(line);
51+
}
52+
53+
void make_symbolic_whole(void* addr, size_t byte_size, char* name) {
54+
55+
}
56+
57+
/*
58+
int main() {
59+
int x;
60+
make_symbolic(&x, 4, "x");
61+
if (x <= 10) {
62+
printf("%d\n", x);
63+
} else {
64+
if (x <= 15) {
65+
printf("%d\n", x);
66+
} else {
67+
printf("%d\n", x);
68+
}
69+
}
70+
return 0;
71+
}
72+
*/

dev-clean/scripts/quicksort.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "../headers/llsc_client.h"
2+
#define SIZE 5
3+
4+
int d[SIZE];
5+
6+
void qsort(int l, int r)
7+
{
8+
if (l < r)
9+
{
10+
int x = d[r];
11+
int j = l - 1;
12+
13+
for (int i = l; i <= r; i++)
14+
{
15+
if (d[i] <= x)
16+
{
17+
j++;
18+
int temp = d[i];
19+
d[i] = d[j];
20+
d[j] = temp;
21+
}
22+
}
23+
24+
qsort(l, j - 1);
25+
qsort(j + 1, r);
26+
}
27+
}
28+
29+
int main()
30+
{
31+
llsc_make_symbolic(d, sizeof(int) * SIZE, "x");
32+
for (int i = 0; i < SIZE; i++) printf("%d,", d[i]);
33+
printf("\n");
34+
qsort(0, SIZE-1);
35+
for (int i = 0; i < SIZE; i++) printf("%d,", d[i]);
36+
printf("\n");
37+
return 0;
38+
}

dev-clean/src/test/scala/sai/llsc/TestLLSC.scala

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class Playground extends TestLLSC {
137137
// testcoreutil, Seq("--cons-indep", "--argv=./echo.bc --sym-stdout --sym-arg 8"), nPath(4971)++status(0)))
138138

139139
//testLLSC(llsc, TestPrg(mp1048576, "mp1mTest", "@f", symArg(20), "--solver=disable", nPath(1048576)))
140+
//testLLSC(llsc, TestPrg(quicksort, "quickSortTest", "@main", noArg, noOpt, nPath(120)))
140141
//testLLSC(llsc, TestPrg(printfTest, "printfTest", "@main", noArg, noOpt, nPath(1)++status(0)))
141142
//testLLSC(llsc, TestPrg(selectTestSym, "selectTest", "@main", noArg, noOpt, nPath(1)))
142143
//testLLSC(llsc, TestPrg(maze, "mazeTest", "@main", noArg, noOpt, nPath(309)))

0 commit comments

Comments
 (0)