Home | History | Annotate | Download | only in test
      1 #
      2 # Copyright (C) 2014 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #      http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 #
     16 
     17 LOCAL_PATH := $(call my-dir)
     18 
     19 define declare-strace-test-target
     20   include $(CLEAR_VARS)
     21   LOCAL_SRC_FILES := $(1)
     22   LOCAL_MULTILIB := both
     23   LOCAL_CFLAGS := -Wno-unused-parameter -Wno-error=return-type
     24   LOCAL_MODULE := strace-$(basename $(1))-test
     25   LOCAL_MODULE_STEM_32 := strace-$(basename $(1))32-test
     26   LOCAL_MODULE_STEM_64 := strace-$(basename $(1))64-test
     27   LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
     28   LOCAL_MODULE_TAGS := tests
     29   LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
     30   include $(BUILD_EXECUTABLE)
     31 endef
     32 
     33 src_files := \
     34     childthread.c \
     35     clone.c \
     36     fork.c \
     37     leaderkill.c \
     38     mmap_offset_decode.c \
     39     mtd.c \
     40     select.c \
     41     sfd.c \
     42     sig.c \
     43     sigkill_rain.c \
     44     sigreturn.c \
     45     skodic.c \
     46     threaded_execve.c \
     47     ubi.c \
     48     vfork.c \
     49     wait_must_be_interruptible.c \
     50 
     51 $(foreach file, $(src_files), $(eval $(call declare-strace-test-target,$(file))))
     52 
     53 # Simple sanity tests meant to be run manually on device. Tests expect that
     54 # strace will report "exit with 0" at the end of the programs. Some tests
     55 # document what string should be expected in the output and for them additional
     56 # checks is made (*-expected output vars)).
     57 #
     58 # Failure should be inspected manually. Usually they require a special test
     59 # setup that can't be easily automated.
     60 #
     61 # adb sync is requreired before running "mm run-strace-tests".
     62 # logs are pulled automatically from the device to the root of the tree
     63 # (strace-log-*)
     64 
     65 childthread-expected-output := 'write(1, "OK\\n",'
     66 clone-expected-output := 'write(1, "original\\n",'
     67 fork-expected-output := 'write(1, "parent\\n",'
     68 leaderkill-expected-output := 'write(1, "OK\\n",'
     69 mmap_offset_decode-expected-output := ''
     70 mtd-expected-output := ''
     71 select-expected-output := ''
     72 sfd-expected-output := ''
     73 sig-expected-output := 'write(2, "qwerty\\n",'
     74 sigkill_rain-expected-output := ''
     75 sigreturn-expected-output := 'RT_1 RT_3 RT_31 RT_32'
     76 skodic-expected-output := ''
     77 threaded_execve-expected-output := ''
     78 ubi-expected-output := ''
     79 vfork-expected-output := 'write(1, "parent\\n",'
     80 wait_must_be_interruptible-expected-output := 'write(1, "Good: wait seems to be correctly"'
     81 
     82 run-strace-%-test: TEST_TMP_DIR := /data/local/tmp
     83 run-strace-%-test:
     84 	@printf >&2 "\n$*: RUNNING...\n" ; \
     85 	adb shell rm -f $(TEST_TMP_DIR)/strace-log-$* ; \
     86 	timeout -s 9 10 adb shell strace -v -f -o$(TEST_TMP_DIR)/strace-log-$* strace-$*-test > strace-log-$*-output ; \
     87 	adb pull $(TEST_TMP_DIR)/strace-log-$* 2> /dev/null ; \
     88 	adb pull $(TEST_TMP_DIR)/strace-log-$*-output 2> /dev/null ; \
     89 	if adb shell cat $(TEST_TMP_DIR)/strace-log-$* | grep "exited with 0" > /dev/null ; \
     90 	then \
     91 		if [ -n $($(shell echo $* | sed 's/[0-9]//g')-expected-output) ] ; then \
     92 			if adb shell cat $(TEST_TMP_DIR)/strace-log-$* | grep $($(shell echo $* | sed 's/[0-9]//g')-expected-output) > /dev/null ; \
     93 				then printf >&2 "$*: PASSED\n" ; \
     94 				else printf >&2 "$*: FAILED\n" ; \
     95 			fi ; \
     96 		else \
     97 			printf >&2 "$*: PASSED\n" ; \
     98 		fi ; \
     99 	else \
    100 		printf >&2 "$*: FAILED\n" ; \
    101 	fi
    102 
    103 adb-sync:
    104 	adb sync
    105 
    106 run-strace32-test: $(foreach file, $(src_files), run-strace-$(basename $(file))32-test)
    107 run-strace64-test: $(foreach file, $(src_files), run-strace-$(basename $(file))64-test)
    108 
    109 run-strace-tests: adb-sync run-strace32-test run-strace64-test
    110