Skip to content

Commit

Permalink
basic8-tracers: added test for MemoryTracer/TBTracer/InstructionCounter
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaly Chipounov <vitaly@cyberhaven.io>
  • Loading branch information
vitaly-cyberhaven authored and vitalych committed Jan 2, 2020
1 parent f1df34a commit 08c392e
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
46 changes: 46 additions & 0 deletions basic8-tracers/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2019, Cyberhaven
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

TARGET=basic8-tracers
SOURCE=main.c

GCC_LINUX=gcc
GCC_WINDOWS64=x86_64-w64-mingw32-gcc
GCC_WINDOWS32=i686-w64-mingw32-gcc

CFLAGS:=-O3 -g -Wall -std=c99 $(CFLAGS)

linux64-$(TARGET): $(SOURCE)
$(GCC_LINUX) -m64 $(CFLAGS) -o "$@" "$^"

linux32-$(TARGET): $(SOURCE)
$(GCC_LINUX) -m32 $(CFLAGS) -o "$@" "$^"

windows64-$(TARGET).exe: $(SOURCE)
$(GCC_WINDOWS64) -m64 $(CFLAGS) -o "$@" "$^"

windows32-$(TARGET).exe: $(SOURCE)
$(GCC_WINDOWS32) -m32 $(CFLAGS) -o "$@" "$^"

TARGETS=linux64-$(TARGET) linux32-$(TARGET) windows64-$(TARGET).exe windows32-$(TARGET).exe

all: $(TARGETS)
clean:
rm -f $(TARGETS)
11 changes: 11 additions & 0 deletions basic8-tracers/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test:
description: "Check that execution tracers work properly"

targets:
- linux32-basic8-tracers
- linux64-basic8-tracers
- windows32-basic8-tracers.exe
- windows64-basic8-tracers.exe

build-options:
post-project-generation-script: fix-config.sh
35 changes: 35 additions & 0 deletions basic8-tracers/fix-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

set -e

echo "Patching s2e-config.lua..."

. ${TESTSUITE_ROOT}/helpers.sh

PROJECT_NAME="$(basename $PROJECT_DIR)"

PLATFORM=$(get_platform "$TARGET")

cat << EOF >> $PROJECT_DIR/s2e-config.lua
add_plugin("MemoryTracer")
pluginsConfig.MemoryTracer = {
traceMemory = true,
traceTlbMisses = true,
tracePageFaults = true,
moduleNames = {"$(basename $TARGET)"}
}
add_plugin("TranslationBlockTracer")
pluginsConfig.TranslationBlockTracer = {
traceTbStart = true,
traceTbEnd = true,
moduleNames = {"$(basename $TARGET)"}
}
add_plugin("InstructionCounter")
pluginsConfig.InstructionCounter = {
moduleNames = {"$(basename $TARGET)"}
}
EOF
40 changes: 40 additions & 0 deletions basic8-tracers/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2019, Cyberhaven
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <s2e/s2e.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>

int main(int argc, char **argv) {
uint32_t value = 0;

char c = 0;
s2e_make_symbolic(&c, sizeof(c), "c");
if (c) {
value = 0xdeadbeef;
printf("1");
} else {
value = 0xbadcafe;
printf("2");
}

s2e_printf("value: %#x", value);
}
25 changes: 25 additions & 0 deletions basic8-tracers/run-tests.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

{% include 'common-run.sh.tpl' %}

s2e run -n {{ project_name }}

grep -q "0xdeadbeef" "$S2E_LAST/debug.txt"
grep -q "0xbadcafe" "$S2E_LAST/debug.txt"

check_coverage {{project_name}} 60

# deadbeef
s2e execution_trace -pp -p 1 {{ project_name }}
grep -q "3735928559" "$S2E_LAST/execution_trace.json"

# badcafe
s2e execution_trace -pp -p 0 {{ project_name }}
grep -q "195939070" "$S2E_LAST/execution_trace.json"

grep -q "TRACE_TB_START" "$S2E_LAST/execution_trace.json"
grep -q "TRACE_TB_END" "$S2E_LAST/execution_trace.json"
grep -q "TRACE_ICOUNT" "$S2E_LAST/execution_trace.json"

s2e forkprofile {{ project_name }} > $S2E_LAST/forkprofile.txt
grep -q -i main.c $S2E_LAST/forkprofile.txt

0 comments on commit 08c392e

Please sign in to comment.