1 #!/bin/bash 2 # 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 7 null_output=`mktemp` 8 actual_output=`mktemp` 9 expected_output=`mktemp` 10 failed=0 11 export FAKEGUDEV_DEVICES 12 13 function test_output() { 14 diff -u --ignore-all-space --ignore-blank-lines ${expected_output} \ 15 ${actual_output} 16 if [ $? -ne 0 ] 17 then 18 echo FAILED 19 failed=$(( failed + 1 )) 20 fi 21 } 22 23 function run_test() { 24 if [ $# -eq 1 ] 25 then 26 FAKEGUDEV_DEVICES= 27 else 28 FAKEGUDEV_DEVICES=$2 29 fi 30 LD_PRELOAD=./libfakegudev.so ./gudev-exercise $1 > ${actual_output} 31 test_output 32 } 33 34 function generate_output_file() { 35 # If two arguments supplied, second device is the parent of the first. 36 cat $1 > ${expected_output} 37 if [ $# -eq 2 ] 38 then 39 echo Parent device:>> ${expected_output} 40 cat $2 >> ${expected_output} 41 fi 42 } 43 44 ./gudev-exercise /dev/null > ${null_output} 45 46 47 echo "TEST: /dev/fake does not appear in test program output" 48 generate_output_file test_files/empty.output 49 run_test /dev/fake 50 51 echo "TEST: /dev/null appears in test program output" 52 generate_output_file ${null_output} 53 run_test /dev/null 54 55 echo "TEST: =mem,null finds /dev/null " 56 generate_output_file ${null_output} 57 run_test =mem,null 58 59 echo "TEST: /sys/devices/virtual/mem/null appears in test program output" 60 generate_output_file ${null_output} 61 run_test /sys/devices/virtual/mem/null 62 63 64 echo "TEST: /dev/fake appears when specified in FAKEGUDEV_DEVICES" 65 generate_output_file test_files/fake.output 66 run_test /dev/fake test_files/fake.dat 67 68 echo "TEST: /dev/null appears when /dev/fake is specified in FAKEGUDEV_DEVICES" 69 generate_output_file ${null_output} 70 run_test /dev/null test_files/fake.dat 71 72 echo "TEST: Device name appears" 73 generate_output_file test_files/fake_name.output 74 run_test /dev/fake test_files/fake_name.dat 75 76 echo "TEST: Driver appears" 77 generate_output_file test_files/fake_driver.output 78 run_test /dev/fake test_files/fake_driver.dat 79 80 echo "TEST: Subsystem appears" 81 generate_output_file test_files/fake_subsystem.output 82 run_test /dev/fake test_files/fake_subsystem.dat 83 84 echo "TEST: Property appears" 85 generate_output_file test_files/fake_property_foo.output 86 run_test /dev/fake test_files/fake_property_foo.dat 87 88 echo "TEST: Several properties appear" 89 generate_output_file test_files/fake_properties.output 90 run_test /dev/fake test_files/fake_properties.dat 91 92 echo "TEST: /dev/fake2 does not appear when only /dev/fake is specified" 93 generate_output_file test_files/empty.output 94 run_test /dev/fake2 test_files/fake.dat 95 96 echo "TEST: /dev/fake2 and /dev/fake both appear when specified" 97 generate_output_file test_files/fake.output 98 run_test /dev/fake test_files/fake_and_fake2.dat 99 generate_output_file test_files/fake2.output 100 run_test /dev/fake2 test_files/fake_and_fake2.dat 101 102 echo "TEST: /dev/fake appears as parent of /dev/fake2" 103 generate_output_file test_files/fake2.output test_files/fake.output 104 run_test /dev/fake2 test_files/fake2_parent_fake.dat 105 106 echo "TEST: Real device /dev/null appears as parent of /dev/fake" 107 generate_output_file test_files/fake.output ${null_output} 108 run_test /dev/fake test_files/fake_parent_null.dat 109 110 echo "TEST: /sys/devices/fake fully fledged" 111 generate_output_file test_files/fake_full.output ${null_output} 112 run_test /dev/fake test_files/fake_full.dat 113 114 echo "TEST: Search for fake device by subsystem and name works" 115 generate_output_file test_files/fake_full.output ${null_output} 116 run_test '=fakesub,fakedevice' test_files/fake_full.dat 117 118 echo "TEST: Search for fake device by sysfs path works" 119 generate_output_file test_files/fake_full.output ${null_output} 120 run_test /sys/devices/virtual/fake test_files/fake_full.dat 121 122 # Can't use handy functions for this test :( 123 echo "TEST: Property appears when queried repeatedly (test caching)" 124 cat test_files/fake.output > ${expected_output} 125 cat test_files/fake.output >> ${expected_output} 126 cat test_files/fake.output >> ${expected_output} 127 FAKEGUDEV_DEVICES=test_files/fake.dat 128 LD_PRELOAD=./libfakegudev.so ./gudev-exercise /dev/fake /dev/fake /dev/fake > \ 129 ${actual_output} 130 test_output 131 132 133 echo 134 echo 135 echo Total errors: ${failed} 136