summaryrefslogtreecommitdiff
path: root/io-tool/sysfs-tests
blob: 7b07955eb5775de1a63260ef4ee84998f64fddca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash

PATH=${PATH}:.

source /usr/lib/mts-io-sysfs/mts-io-sysfs-inc.sh

yesno() {
  if [ $# -ne 1 ]; then
    echo "yesno question"
    exit 99
  fi

  local question=${1}

  while :
  do
    echo -n "${question}? [y/n] "
    read line
    local line=$(echo ${line} | tr A-Z a-z)
    case "${line}" in
    y)
      return 0
      ;;
    n)
      return 1
      ;;
    *)
      ;;
    esac
  done
}

store_assert() {
  if [ $# -ne 2 ]; then
    log_error "store_assert name value"
    exit 99
  fi

  local name=${1}
  local value=${2}

  local old_value="$(cat ${SYSFS_PLATFORM_DIR}/${name})"
  store ${name} "${value}"
  local new_value="$(cat ${SYSFS_PLATFORM_DIR}/${name})"

  if [ "${new_value}" != "${value}" ]; then
    log_error "${name}: '${new_value}' != '${value}'"
    exit 1
  fi
}

show_assert() {
  if [ $# -ne 2 ]; then
    log_error "show_assert name value"
    exit 99
  fi

  local name=${1}
  local expected_value=${2}

  log_info "checking if ${name} is '${expected_value}'"

  local actual_value="$(show ${name})"

  if [ "${expected_value}" != "${actual_value}" ]; then
    log_error "${name}: '${expected_value}' != '${actual_value}'"
    exit 1
  fi
}

show_assert_in_set() {
  if [ $# -lt 2 ]; then
    log_error "show_assert_in_set name value0 [value1 ...]"
    exit 99
  fi

  local name=${1}
  shift

  log_info "checking if ${name} is in set [$*]"

  local actual_value="$(show ${name})"

  for value in "$@"; do
    if [ "${value}" = "${actual_value}" ]; then
      log_info "${name} is '${actual_value}'"
      return
    fi
  done

  log_info "${name} is '${actual_value}'"

  exit 1
}

VERBOSE=true

echo none > /sys/devices/platform/leds-gpio/leds/status/trigger

modprobe -r mts-io
modprobe mts-io

sleep 2

show_assert_in_set board-temperature {30..40}
store board-temperature 1000
show_assert_in_set board-temperature {30..40}

#for ((i = 0; i < 1000; i++)); do
#  show_assert_in_set board-temperature {30..40}
#done

show_assert radio-reset 1
log_info "resetting radio..."
store radio-reset 0
sleep 2
show_assert radio-reset 1
log_info "radio reset"

show_assert eth0-enabled 1
store_assert eth0-enabled 0
sleep 2
if ! yesno "Are the ethernet LEDs off"; then
  exit 1
fi
store_assert eth0-enabled 1
sleep 2
if ! yesno "Are the ethernet LEDs on"; then
  exit 1
fi

show_assert extserial-dcd 0
store_assert extserial-dcd 1
store_assert extserial-dcd 0

show_assert extserial-ri 0
store_assert extserial-ri 1
store_assert extserial-ri 0

show_assert led-sig1 0
store_assert led-sig1 1
store_assert led-sig1 0

show_assert led-sdk-c 0
store_assert led-sdk-c 1
store_assert led-sdk-c 0

show_assert led-sig2 0
store_assert led-sig2 1
store_assert led-sig2 0

show_assert led-sdk-d 0
store_assert led-sdk-d 1
store_assert led-sdk-d 0

show_assert led-sig3 0
store_assert led-sig3 1
store_assert led-sig3 0

show_assert led-sdk-e 0
store_assert led-sdk-e 1
store_assert led-sdk-e 0

show_assert led-cd 0
store_assert led-cd 1
store_assert led-cd 0

show_assert led-sdk-b 0
store_assert led-sdk-b 1
store_assert led-sdk-b 0

show_assert led-status 0
store_assert led-status 1
store_assert led-status 0

show_assert led-sdk-a 0
store_assert led-sdk-a 1
store_assert led-sdk-a 0

show_assert reset 0
store reset 1
show_assert reset 0

show_assert reset-monitor "-1 10 12"

exit 0