sysctl.sh (eb965eda1cabf26e62afc07a06cdf2fd5aaa2906) | sysctl.sh (2920fad3a5d394b66011c7f35c7b05278354055e) |
---|---|
1#!/bin/bash 2# Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org> 3# 4# This program is free software; you can redistribute it and/or modify it 5# under the terms of the GNU General Public License as published by the Free 6# Software Foundation; either version 2 of the License, or at your option any 7# later version; or, when distributed separately from the Linux kernel or 8# when incorporated into other software packages, subject to the following --- 18 unchanged lines hidden (view full) --- 27# TEST_COUNT: number of times we should run the test 28# ENABLED: 1 if enabled, 0 otherwise 29# 30# Once these are enabled please leave them as-is. Write your own test, 31# we have tons of space. 32ALL_TESTS="0001:1:1" 33ALL_TESTS="$ALL_TESTS 0002:1:1" 34ALL_TESTS="$ALL_TESTS 0003:1:1" | 1#!/bin/bash 2# Copyright (C) 2017 Luis R. Rodriguez <mcgrof@kernel.org> 3# 4# This program is free software; you can redistribute it and/or modify it 5# under the terms of the GNU General Public License as published by the Free 6# Software Foundation; either version 2 of the License, or at your option any 7# later version; or, when distributed separately from the Linux kernel or 8# when incorporated into other software packages, subject to the following --- 18 unchanged lines hidden (view full) --- 27# TEST_COUNT: number of times we should run the test 28# ENABLED: 1 if enabled, 0 otherwise 29# 30# Once these are enabled please leave them as-is. Write your own test, 31# we have tons of space. 32ALL_TESTS="0001:1:1" 33ALL_TESTS="$ALL_TESTS 0002:1:1" 34ALL_TESTS="$ALL_TESTS 0003:1:1" |
35ALL_TESTS="$ALL_TESTS 0004:1:1" |
|
35 36test_modprobe() 37{ 38 if [ ! -d $DIR ]; then 39 echo "$0: $DIR not present" >&2 40 echo "You must have the following enabled in your kernel:" >&2 41 cat $TEST_DIR/config >&2 42 exit 1 --- 38 unchanged lines hidden (view full) --- 81 PAGE_SIZE=$(getconf PAGESIZE) 82 fi 83 if [ -z $MAX_DIGITS ]; then 84 MAX_DIGITS=$(($PAGE_SIZE/8)) 85 fi 86 if [ -z $INT_MAX ]; then 87 INT_MAX=$(getconf INT_MAX) 88 fi | 36 37test_modprobe() 38{ 39 if [ ! -d $DIR ]; then 40 echo "$0: $DIR not present" >&2 41 echo "You must have the following enabled in your kernel:" >&2 42 cat $TEST_DIR/config >&2 43 exit 1 --- 38 unchanged lines hidden (view full) --- 82 PAGE_SIZE=$(getconf PAGESIZE) 83 fi 84 if [ -z $MAX_DIGITS ]; then 85 MAX_DIGITS=$(($PAGE_SIZE/8)) 86 fi 87 if [ -z $INT_MAX ]; then 88 INT_MAX=$(getconf INT_MAX) 89 fi |
90 if [ -z $UINT_MAX ]; then 91 UINT_MAX=$(getconf UINT_MAX) 92 fi |
|
89} 90 91test_reqs() 92{ 93 uid=$(id -u) 94 if [ $uid -ne 0 ]; then 95 echo $msg must be run as root >&2 96 exit 0 --- 27 unchanged lines hidden (view full) --- 124 TRIGGER=$(basename ${TARGET}) 125 case "$TRIGGER" in 126 int_0001) 127 VAL="60" 128 ;; 129 int_0002) 130 VAL="1" 131 ;; | 93} 94 95test_reqs() 96{ 97 uid=$(id -u) 98 if [ $uid -ne 0 ]; then 99 echo $msg must be run as root >&2 100 exit 0 --- 27 unchanged lines hidden (view full) --- 128 TRIGGER=$(basename ${TARGET}) 129 case "$TRIGGER" in 130 int_0001) 131 VAL="60" 132 ;; 133 int_0002) 134 VAL="1" 135 ;; |
136 uint_0001) 137 VAL="314" 138 ;; |
|
132 string_0001) 133 VAL="(none)" 134 ;; 135 *) 136 ;; 137 esac 138 echo -n $VAL > $TARGET 139} --- 200 unchanged lines hidden (view full) --- 340 echo "FAIL" >&2 341 rc=1 342 else 343 echo "ok" 344 fi 345 test_rc 346} 347 | 139 string_0001) 140 VAL="(none)" 141 ;; 142 *) 143 ;; 144 esac 145 echo -n $VAL > $TARGET 146} --- 200 unchanged lines hidden (view full) --- 347 echo "FAIL" >&2 348 rc=1 349 else 350 echo "ok" 351 fi 352 test_rc 353} 354 |
355# You are using an unsigned int 356run_limit_digit_uint() 357{ 358 echo -n "Testing UINT_MAX works ..." 359 reset_vals 360 TEST_STR="$UINT_MAX" 361 echo -n $TEST_STR > $TARGET 362 363 if ! verify "${TARGET}"; then 364 echo "FAIL" >&2 365 rc=1 366 else 367 echo "ok" 368 fi 369 test_rc 370 371 echo -n "Testing UINT_MAX + 1 will fail as expected..." 372 reset_vals 373 TEST_STR=$(($UINT_MAX+1)) 374 echo -n $TEST_STR > $TARGET 2> /dev/null 375 376 if verify "${TARGET}"; then 377 echo "FAIL" >&2 378 rc=1 379 else 380 echo "ok" 381 fi 382 test_rc 383 384 echo -n "Testing negative values will not work as expected ..." 385 reset_vals 386 TEST_STR="-3" 387 echo -n $TEST_STR > $TARGET 2> /dev/null 388 389 if verify "${TARGET}"; then 390 echo "FAIL" >&2 391 rc=1 392 else 393 echo "ok" 394 fi 395 test_rc 396} 397 |
|
348run_stringtests() 349{ 350 echo -n "Writing entire sysctl in short writes ... " 351 set_orig 352 dd if="${TEST_FILE}" of="${TARGET}" bs=1 2>/dev/null 353 if ! verify "${TARGET}"; then 354 echo "FAIL" >&2 355 rc=1 --- 89 unchanged lines hidden (view full) --- 445 ORIG=$(cat "${TARGET}") 446 TEST_STR=$(( $ORIG + 1 )) 447 448 run_numerictests 449 run_limit_digit 450 run_limit_digit_int 451} 452 | 398run_stringtests() 399{ 400 echo -n "Writing entire sysctl in short writes ... " 401 set_orig 402 dd if="${TEST_FILE}" of="${TARGET}" bs=1 2>/dev/null 403 if ! verify "${TARGET}"; then 404 echo "FAIL" >&2 405 rc=1 --- 89 unchanged lines hidden (view full) --- 495 ORIG=$(cat "${TARGET}") 496 TEST_STR=$(( $ORIG + 1 )) 497 498 run_numerictests 499 run_limit_digit 500 run_limit_digit_int 501} 502 |
503sysctl_test_0004() 504{ 505 TARGET="${SYSCTL}/uint_0001" 506 reset_vals 507 ORIG=$(cat "${TARGET}") 508 TEST_STR=$(( $ORIG + 1 )) 509 510 run_numerictests 511 run_limit_digit 512 run_limit_digit_uint 513} 514 |
|
453list_tests() 454{ 455 echo "Test ID list:" 456 echo 457 echo "TEST_ID x NUM_TEST" 458 echo "TEST_ID: Test ID" 459 echo "NUM_TESTS: Number of recommended times to run the test" 460 echo 461 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" 462 echo "0002 x $(get_test_count 0002) - tests proc_dostring()" 463 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" | 515list_tests() 516{ 517 echo "Test ID list:" 518 echo 519 echo "TEST_ID x NUM_TEST" 520 echo "TEST_ID: Test ID" 521 echo "NUM_TESTS: Number of recommended times to run the test" 522 echo 523 echo "0001 x $(get_test_count 0001) - tests proc_dointvec_minmax()" 524 echo "0002 x $(get_test_count 0002) - tests proc_dostring()" 525 echo "0003 x $(get_test_count 0003) - tests proc_dointvec()" |
526 echo "0004 x $(get_test_count 0004) - tests proc_douintvec()" |
|
464} 465 466test_reqs 467 468usage() 469{ 470 NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .) 471 let NUM_TESTS=$NUM_TESTS+1 --- 151 unchanged lines hidden --- | 527} 528 529test_reqs 530 531usage() 532{ 533 NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .) 534 let NUM_TESTS=$NUM_TESTS+1 --- 151 unchanged lines hidden --- |