Skip to content
Snippets Groups Projects
Commit 7225037d authored by Matthew McGill's avatar Matthew McGill
Browse files

getting rid of test_fib until i can debug the runner

Former-commit-id: a9571a2d5ab471fa8be721ebdc521769be8c73fd
parent 04a251e5
No related branches found
No related tags found
No related merge requests found
......@@ -162,25 +162,21 @@ test_foo-ubuntu18:
- ubuntu18
variables:
OS: 'ubuntu18'
#
# CFI test_fib
#
# template
.test_fib: &test_fib
stage: test
script:
- ./cicd_tests/test_fib.sh
test_fib-ubuntu18:
<<: *test_fib
test_foo-ubuntu16:
<<: *test_foo
tags:
- ubuntu18
- ubuntu16
variables:
OS: 'ubuntu18'
OS: 'ubuntu16'
test_foo-centos75:
<<: *test_foo
tags:
- centos75
variables:
OS: 'centos75'
#
# elfdep test
......
#!/bin/bash
set -x
set -e
trap clean EXIT
cd $CICD_MODULE_WORK_DIR/peasoup_umbrella
source set_env_vars
cd ./security_transforms/tools/selective_cfi/tests/cicd_tests/fib_src
source ../../cfi_smokescreen_configs.sh
get_correct()
{
cp libfib.so.orig libfib.so
cp libfib2.so.orig libfib2.so
# for fib.exe, a non-zero exit status can indicate success
set +e
./fib.exe $1 > correct
echo $? >> correct
set -e
}
test()
{
echo running test $1 $2 $3 $4
n=$2
get_correct $n
cp $3 libfib.so
cp $4 libfib2.so
# for fib.exe, a non-zero exit status can indicate success
set +e
./$1 $n > out
echo $? >> out
set -e
cmp out correct
}
build()
{
gcc -o libfib.so libfib.c -w -shared -fPIC
gcc -o libfib2.so libfib2.c -w -shared -fPIC
gcc -o fib.exe fib.c -w -L. -lfib -lfib2
gcc -o fib.exe.pie fib.c -fPIC -fpie -pie -w -L. -lfib -lfib2
mv libfib.so libfib.so.orig
mv libfib2.so libfib2.so.orig
}
protect()
{
files=(libfib.so.orig libfib2.so.orig fib.exe fib.exe.pie)
libfib_so_orig_varients=(libfib.so.orig)
libfib2_so_orig_varients=(libfib2.so.orig)
fib_exe_varients=(fib.exe)
fib_exe_pie_varients=(fib.exe.pie)
for file in "${files[@]}"; do
for config in "${configs[@]}"; do
echo Protecting file "$file" with config "$config"
"$config" ./"$file" ./"$file"".""$config"
varient_array_name="$(echo "$file" | sed -e 's/\./_/g')""_varients"
declare -n varient_array="$varient_array_name"
varient_array+=("$file"".""$config")
done
done
}
clean()
{
set +e
set +x
rm out >> /dev/null 2>&1
rm correct >> /dev/null 2>&1
rm -Rf fib.exe* peasoup_exe* lib*.so* >> /dev/null 2>&1
for config in "${configs[@]}"; do
rm *."$config" >> /dev/null 2>&1
done
}
main()
{
build
protect
fib_varients=("${fib_exe_varients[@]}" "${fib_exe_pie_varients[@]}")
for fib_varient in "${fib_varients[@]}"; do
for libfib_varient in "${libfib_so_orig_varients[@]}"; do
for libfib2_varient in "${libfib2_so_orig_varients[@]}"; do
for i in {2..6}; do
test "$fib_varient" $i "$libfib_varient" "$libfib2_varient"
done
done
done
done
exit 0
}
main $*
#include <stdio.h>
extern int fib();
extern int fib2();
extern int fibp(int n, int (*)(int,int));
int add(int n1, int n2)
{
if (n1 == 0)
return n2;
else if (n2 == 0)
return n1;
else if (n1 == 2)
return add(1, add(1, n2));
else
return n1 + add(0, n2);
}
main(int argc, char **argv)
{
int x = 3;
int f = 0;
if (argc >= 2)
x = atoi(argv[1]);
if (x <= 2)
f = fib_main(x);
if (x == 3)
f = fib2(x);
else if (x == 4)
f = fib_simple(x);
else if (x == 5)
f = fibp(x, &add);
else
f = fib(x);
printf("Fibonacci(%d) = %d\n", x, f);
return f;
}
fib_main(int f) {
if (f <= 2)
return 1;
else
return fib_simple(f-1) + fib_main(f-2);
}
fib_simple(int f) {
if (f <= 2)
return 1;
else
return fib_simple(f-1) + fib_simple(f-2);
}
extern int fib_main();
extern int fib2();
extern int fib2p(int n, int (*)(int,int));
int add2(int n1, int n2)
{
if (n1 == 0)
return n2;
else if (n2 == 0)
return n1;
else if (n2 == 2)
return add2(add2(n1, 1),1);
else
return add2(0, n2) + add2(n1, 0);
}
int fib(int n)
{
if (n <= 2)
return 1;
else
return fib_main(n-1) + fib2(n-2);
}
int fibp(int n, int (*addp)(int,int))
{
if (n <= 2)
return 1;
else
return (*addp)(fib_main(n-1),fib2p(n-2,&add2));
}
extern int fib_main();
extern int fib();
int fib2(int n)
{
if (n <= 2)
return 1;
else
return fib2(n-1) + fib_main(n-2);
}
int fib2p(int n, int (*addp)(int,int))
{
if (n <= 2)
return (*addp)(1,0);
else
return (*addp)(fib2(n-1),fib2p(n-2, addp));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment