• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7null_output=`mktemp`
8actual_output=`mktemp`
9expected_output=`mktemp`
10failed=0
11export FAKEGUDEV_DEVICES
12
13function 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
23function 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
34function 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
47echo "TEST: /dev/fake does not appear in test program output"
48generate_output_file test_files/empty.output
49run_test /dev/fake
50
51echo "TEST: /dev/null appears in test program output"
52generate_output_file ${null_output}
53run_test /dev/null
54
55echo "TEST: =mem,null finds /dev/null "
56generate_output_file ${null_output}
57run_test =mem,null
58
59echo "TEST: /sys/devices/virtual/mem/null appears in test program output"
60generate_output_file ${null_output}
61run_test /sys/devices/virtual/mem/null
62
63
64echo "TEST: /dev/fake appears when specified in FAKEGUDEV_DEVICES"
65generate_output_file test_files/fake.output
66run_test /dev/fake test_files/fake.dat
67
68echo "TEST: /dev/null appears when /dev/fake is specified in FAKEGUDEV_DEVICES"
69generate_output_file ${null_output}
70run_test /dev/null test_files/fake.dat
71
72echo "TEST: Device name appears"
73generate_output_file test_files/fake_name.output
74run_test /dev/fake test_files/fake_name.dat
75
76echo "TEST: Driver appears"
77generate_output_file test_files/fake_driver.output
78run_test /dev/fake test_files/fake_driver.dat
79
80echo "TEST: Subsystem appears"
81generate_output_file test_files/fake_subsystem.output
82run_test /dev/fake test_files/fake_subsystem.dat
83
84echo "TEST: Property appears"
85generate_output_file test_files/fake_property_foo.output
86run_test /dev/fake test_files/fake_property_foo.dat
87
88echo "TEST: Several properties appear"
89generate_output_file test_files/fake_properties.output
90run_test /dev/fake test_files/fake_properties.dat
91
92echo "TEST: /dev/fake2 does not appear when only /dev/fake is specified"
93generate_output_file test_files/empty.output
94run_test /dev/fake2 test_files/fake.dat
95
96echo "TEST: /dev/fake2 and /dev/fake both appear when specified"
97generate_output_file test_files/fake.output
98run_test /dev/fake test_files/fake_and_fake2.dat
99generate_output_file test_files/fake2.output
100run_test /dev/fake2 test_files/fake_and_fake2.dat
101
102echo "TEST: /dev/fake appears as parent of /dev/fake2"
103generate_output_file test_files/fake2.output test_files/fake.output
104run_test /dev/fake2 test_files/fake2_parent_fake.dat
105
106echo "TEST: Real device /dev/null appears as parent of /dev/fake"
107generate_output_file test_files/fake.output ${null_output}
108run_test /dev/fake test_files/fake_parent_null.dat
109
110echo "TEST: /sys/devices/fake fully fledged"
111generate_output_file test_files/fake_full.output ${null_output}
112run_test /dev/fake test_files/fake_full.dat
113
114echo "TEST: Search for fake device by subsystem and name works"
115generate_output_file test_files/fake_full.output ${null_output}
116run_test '=fakesub,fakedevice' test_files/fake_full.dat
117
118echo "TEST: Search for fake device by sysfs path works"
119generate_output_file test_files/fake_full.output ${null_output}
120run_test /sys/devices/virtual/fake test_files/fake_full.dat
121
122# Can't use handy functions for this test :(
123echo "TEST: Property appears when queried repeatedly (test caching)"
124cat test_files/fake.output > ${expected_output}
125cat test_files/fake.output >> ${expected_output}
126cat test_files/fake.output >> ${expected_output}
127FAKEGUDEV_DEVICES=test_files/fake.dat
128LD_PRELOAD=./libfakegudev.so ./gudev-exercise /dev/fake /dev/fake /dev/fake > \
129  ${actual_output}
130test_output
131
132
133echo
134echo
135echo Total errors: ${failed}
136