1858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes#
2858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# Copyright (C) 2014 The Android Open Source Project
3858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes#
4858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# Licensed under the Apache License, Version 2.0 (the "License");
5858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# you may not use this file except in compliance with the License.
6858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# You may obtain a copy of the License at
7858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes#
8858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes#      http://www.apache.org/licenses/LICENSE-2.0
9858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes#
10858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# Unless required by applicable law or agreed to in writing, software
11858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# distributed under the License is distributed on an "AS IS" BASIS,
12858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# See the License for the specific language governing permissions and
14858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes# limitations under the License.
15858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes#
16858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes
17858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott HughesLOCAL_PATH := $(call my-dir)
18858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes
19858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughesdefine declare-strace-test-target
20858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  include $(CLEAR_VARS)
21858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  LOCAL_SRC_FILES := $(1)
22ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin  LOCAL_MULTILIB := both
23fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes  LOCAL_CFLAGS := -Wno-unused-parameter -Wno-error=return-type
24858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  LOCAL_MODULE := strace-$(basename $(1))-test
25ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin  LOCAL_MODULE_STEM_32 := strace-$(basename $(1))32-test
26ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin  LOCAL_MODULE_STEM_64 := strace-$(basename $(1))64-test
27858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
28858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  LOCAL_MODULE_TAGS := tests
29858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
30858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes  include $(BUILD_EXECUTABLE)
31858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughesendef
32858a5c77bfa0aef527442d66432ab217b2e9beb8Elliott Hughes
33fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughessrc_files := \
34fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    childthread.c \
35fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    clone.c \
36fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    fork.c \
37fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    leaderkill.c \
38fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    mmap_offset_decode.c \
39fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    mtd.c \
40fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    select.c \
41fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    sfd.c \
42fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    sig.c \
43fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    sigkill_rain.c \
44fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    sigreturn.c \
45fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    skodic.c \
46fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    threaded_execve.c \
47fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    ubi.c \
48fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    vfork.c \
49fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes    wait_must_be_interruptible.c \
50fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes
51fa8e439c1559c81e9a30e8ea4a81554294333f05Elliott Hughes$(foreach file, $(src_files), $(eval $(call declare-strace-test-target,$(file))))
5218612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle
5318612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# Simple sanity tests meant to be run manually on device. Tests expect that
5418612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# strace will report "exit with 0" at the end of the programs. Some tests
5518612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# document what string should be expected in the output and for them additional
5618612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# checks is made (*-expected output vars)).
5718612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle#
5818612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# Failure should be inspected manually. Usually they require a special test
5918612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# setup that can't be easily automated.
6018612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle#
6118612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# adb sync is requreired before running "mm run-strace-tests".
6218612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# logs are pulled automatically from the device to the root of the tree
6318612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle# (strace-log-*)
6418612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle
6518612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlechildthread-expected-output := 'write(1, "OK\\n",'
6618612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravleclone-expected-output := 'write(1, "original\\n",'
6718612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlefork-expected-output := 'write(1, "parent\\n",'
6818612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravleleaderkill-expected-output := 'write(1, "OK\\n",'
6918612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlemmap_offset_decode-expected-output := ''
7018612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlemtd-expected-output := ''
7118612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravleselect-expected-output := ''
7218612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlesfd-expected-output := ''
7318612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlesig-expected-output := 'write(2, "qwerty\\n",'
7418612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlesigkill_rain-expected-output := ''
7518612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlesigreturn-expected-output := 'RT_1 RT_3 RT_31 RT_32'
7618612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravleskodic-expected-output := ''
7718612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlethreaded_execve-expected-output := ''
7818612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravleubi-expected-output := ''
7918612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlevfork-expected-output := 'write(1, "parent\\n",'
8018612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlewait_must_be_interruptible-expected-output := 'write(1, "Good: wait seems to be correctly"'
8118612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle
8218612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlerun-strace-%-test: TEST_TMP_DIR := /data/local/tmp
8318612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravlerun-strace-%-test:
8418612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	@printf >&2 "\n$*: RUNNING...\n" ; \
8518612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	adb shell rm -f $(TEST_TMP_DIR)/strace-log-$* ; \
86ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin	timeout -s 9 10 adb shell strace -v -f -o$(TEST_TMP_DIR)/strace-log-$* strace-$*-test > strace-log-$*-output ; \
8718612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	adb pull $(TEST_TMP_DIR)/strace-log-$* 2> /dev/null ; \
88ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin	adb pull $(TEST_TMP_DIR)/strace-log-$*-output 2> /dev/null ; \
8918612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	if adb shell cat $(TEST_TMP_DIR)/strace-log-$* | grep "exited with 0" > /dev/null ; \
9018612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	then \
91ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin		if [ -n $($(shell echo $* | sed 's/[0-9]//g')-expected-output) ] ; then \
92ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin			if adb shell cat $(TEST_TMP_DIR)/strace-log-$* | grep $($(shell echo $* | sed 's/[0-9]//g')-expected-output) > /dev/null ; \
9318612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle				then printf >&2 "$*: PASSED\n" ; \
9418612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle				else printf >&2 "$*: FAILED\n" ; \
9518612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle			fi ; \
9618612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle		else \
9718612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle			printf >&2 "$*: PASSED\n" ; \
9818612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle		fi ; \
9918612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	else \
10018612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle		printf >&2 "$*: FAILED\n" ; \
10118612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	fi
10218612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle
10318612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravleadb-sync:
10418612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle	adb sync
10518612f277eb2aec2d0f647c4b936d9f49330a434Calin Juravle
106ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yinrun-strace32-test: $(foreach file, $(src_files), run-strace-$(basename $(file))32-test)
107ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yinrun-strace64-test: $(foreach file, $(src_files), run-strace-$(basename $(file))64-test)
108ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yin
109ee295a46deb10e5dd7055f30202fc538660c52ebFengwei Yinrun-strace-tests: adb-sync run-strace32-test run-strace64-test
110