From 3498d52d7eb33b33b16d0ceef44ed3b52debdd5c Mon Sep 17 00:00:00 2001 From: "Sergey V. Lobanov" Date: Mon, 19 Aug 2024 20:01:11 +0000 Subject: tests: add pcre negative cases, improve pcre-related code test coverage these test cases will help for pcre2 migration (issue #173) --- accel-pppd/ctrl/pppoe/pppoe.c | 2 + tests/accel-pppd/general/test_basic.py | 83 ++++++++++++++++++++++ .../accel-pppd/general/test_pcre_negative_cases.py | 55 ++++++++++++++ .../dhcpv4/test_ipoe_shared_session_wo_auth.py | 4 +- .../accel-pppd/pppoe/test_pppoe_session_wo_auth.py | 2 +- tests/accel-pppd/test_basic.py | 83 ---------------------- 6 files changed, 143 insertions(+), 86 deletions(-) create mode 100644 tests/accel-pppd/general/test_basic.py create mode 100644 tests/accel-pppd/general/test_pcre_negative_cases.py delete mode 100644 tests/accel-pppd/test_basic.py diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index dd623acc..8678db80 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -1394,6 +1394,8 @@ static void pppoe_add_interface_re(const char *opt, void *cli) re = pcre_compile2(pattern, 0, NULL, &pcre_err, &pcre_offset, NULL); if (!re) { + if (cli) + cli_sendv(cli, "pppoe: %s at %i\r\n", pcre_err, pcre_offset); log_error("pppoe: %s at %i\r\n", pcre_err, pcre_offset); return; } diff --git a/tests/accel-pppd/general/test_basic.py b/tests/accel-pppd/general/test_basic.py new file mode 100644 index 00000000..2b2c6f71 --- /dev/null +++ b/tests/accel-pppd/general/test_basic.py @@ -0,0 +1,83 @@ +import pytest +from common import process + + +def test_accel_pppd_version(accel_pppd): + (exit, out, err) = process.run([accel_pppd, "--version"]) + + # test that accel-pppd --version exits with code 0, prints + # nothing to stdout and prints to stdout + assert exit == 0 and err == "" and "accel-ppp " in out and len(out.split(" ")) == 2 + + +@pytest.fixture() +def accel_pppd_config(): + return """ + [modules] + log_file + log_syslog + log_tcp + #log_pgsql + + pptp + l2tp + sstp + pppoe + ipoe + + auth_mschap_v2 + auth_mschap_v1 + auth_chap_md5 + auth_pap + + radius + chap-secrets + + ippool + + pppd_compat + shaper + #net-snmp + logwtmp + connlimit + + ipv6_nd + ipv6_dhcp + ipv6pool + + [core] + log-error=/dev/stderr + + [log] + log-debug=/dev/stdout + log-file=/dev/stdout + log-emerg=/dev/stderr + level=5 + + [cli] + tcp=127.0.0.1:2001 + + [pppoe] + + [client-ip-range] + 10.0.0.0/8 + + [radius] + """ + + +# load all modules and check that accel-pppd replies to 'show stat' command +def test_load_all_modules(accel_pppd_instance, accel_cmd): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + (exit_sh_stat, out_sh_stat, err_sh_stat) = process.run([accel_cmd, "show stat"]) + + # test that 'show stat' has no errors and contains 'uptime' + assert ( + exit_sh_stat == 0 + and len(out_sh_stat) > 1 + and err_sh_stat == "" + and "uptime" in out_sh_stat + ) diff --git a/tests/accel-pppd/general/test_pcre_negative_cases.py b/tests/accel-pppd/general/test_pcre_negative_cases.py new file mode 100644 index 00000000..7ad05ff3 --- /dev/null +++ b/tests/accel-pppd/general/test_pcre_negative_cases.py @@ -0,0 +1,55 @@ +import pytest +from common import process + + +@pytest.fixture() +def accel_pppd_config(): + return """ + [modules] + pppoe + + [log] + log-debug=/dev/stdout + level=5 + + [cli] + tcp=127.0.0.1:2001 + """ + + +# test pcre-related negative cases +def test_pcre_negative_cases(accel_pppd_instance, accel_cmd): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + (exit_sh_sess, out_sh_sess, err_sh_sess) = process.run([accel_cmd, "show sessions match username 00("]) + # test that 'show sessions' with invalid regexp reports the issue and error position + assert ( + exit_sh_sess == 0 + and len(out_sh_sess) > 0 + and err_sh_sess == "" + and "match: " in out_sh_sess + and "at 3" in out_sh_sess + ) + + + (exit_iface_add, out_iface_add, err_iface_add) = process.run([accel_cmd, "pppoe interface add re:000("]) + # test that 'pppoe interface add' with invalid regexp reports the issue and error position + assert ( + exit_iface_add == 0 + and len(out_iface_add) > 0 + and err_iface_add == "" + and "pppoe: " in out_iface_add + and "at 4" in out_iface_add + ) + + (exit_term, out_term, err_term) = process.run([accel_cmd, "terminate match username 00("]) + # test that 'terminate' with invalid regexp reports the issue and error position + assert ( + exit_term == 0 + and len(out_term) > 0 + and err_term == "" + and "match: " in out_term + and "at 3" in out_term + ) diff --git a/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py b/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py index 104e4e9b..da9a40e0 100644 --- a/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py +++ b/tests/accel-pppd/ipoe/dhcpv4/test_ipoe_shared_session_wo_auth.py @@ -28,8 +28,8 @@ def accel_pppd_config(veth_pair_netns): noauth=1 shared=1 gw-ip-address=192.0.2.1/24 - interface=""" - + veth_pair_netns["veth_a"] + interface=re:.""" + + veth_pair_netns["veth_a"][1:] ) diff --git a/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py b/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py index 0c8aa2c0..5ce870dd 100644 --- a/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py +++ b/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py @@ -69,7 +69,7 @@ def test_pppoe_session_wo_auth(pppd_instance, accel_cmd): (exit, out, err) = process.run( [ accel_cmd, - "show sessions match username loginAB username,ip,state", + "show sessions match username log.nAB username,ip,state", ] ) assert exit == 0 # accel-cmd fails diff --git a/tests/accel-pppd/test_basic.py b/tests/accel-pppd/test_basic.py deleted file mode 100644 index 2b2c6f71..00000000 --- a/tests/accel-pppd/test_basic.py +++ /dev/null @@ -1,83 +0,0 @@ -import pytest -from common import process - - -def test_accel_pppd_version(accel_pppd): - (exit, out, err) = process.run([accel_pppd, "--version"]) - - # test that accel-pppd --version exits with code 0, prints - # nothing to stdout and prints to stdout - assert exit == 0 and err == "" and "accel-ppp " in out and len(out.split(" ")) == 2 - - -@pytest.fixture() -def accel_pppd_config(): - return """ - [modules] - log_file - log_syslog - log_tcp - #log_pgsql - - pptp - l2tp - sstp - pppoe - ipoe - - auth_mschap_v2 - auth_mschap_v1 - auth_chap_md5 - auth_pap - - radius - chap-secrets - - ippool - - pppd_compat - shaper - #net-snmp - logwtmp - connlimit - - ipv6_nd - ipv6_dhcp - ipv6pool - - [core] - log-error=/dev/stderr - - [log] - log-debug=/dev/stdout - log-file=/dev/stdout - log-emerg=/dev/stderr - level=5 - - [cli] - tcp=127.0.0.1:2001 - - [pppoe] - - [client-ip-range] - 10.0.0.0/8 - - [radius] - """ - - -# load all modules and check that accel-pppd replies to 'show stat' command -def test_load_all_modules(accel_pppd_instance, accel_cmd): - - # test that accel-pppd started successfully - assert accel_pppd_instance - - (exit_sh_stat, out_sh_stat, err_sh_stat) = process.run([accel_cmd, "show stat"]) - - # test that 'show stat' has no errors and contains 'uptime' - assert ( - exit_sh_stat == 0 - and len(out_sh_stat) > 1 - and err_sh_stat == "" - and "uptime" in out_sh_stat - ) -- cgit v1.2.3 From fd7d220aed51e2082e19630106f43071e65e8f9c Mon Sep 17 00:00:00 2001 From: "Sergey V. Lobanov" Date: Mon, 19 Aug 2024 20:27:14 +0000 Subject: tests: fix execution order --- .github/workflows/run-tests.yml | 16 ++++++++-------- tests/README.md | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 30a1e04a..a50a7a53 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -120,7 +120,7 @@ jobs: libpcre3-dev libssl-dev liblua5.1-0-dev kmod python3-pip libxml2-dev libxslt1-dev zlib1g-dev iproute2 ppp pppoe isc-dhcp-client timelimit && - (sudo pip3 install pytest pytest-dependency || sudo pip3 install --break-system-packages pytest pytest-dependency)" + (sudo pip3 install pytest pytest-dependency pytest-order || sudo pip3 install --break-system-packages pytest pytest-dependency pytest-order)" - name: Copy source code to target OS run: | tar -Jcf accel-ppp.tar.xz accel-ppp @@ -139,7 +139,7 @@ jobs: timeout-minutes: 5 run: > ssh -i ssh-key -p2222 user@localhost "cd accel-ppp/tests && - sudo python3 -m pytest -Wall -v -m \"not ipoe_driver and not vlan_mon_driver\"" + sudo python3 -m pytest -Wall --order-dependencies -v -m \"not ipoe_driver and not vlan_mon_driver\"" - name: Display processes and dmesg after tests if: ${{ always() }} run: > @@ -157,7 +157,7 @@ jobs: if: ${{ always() }} run: > ssh -i ssh-key -p2222 user@localhost "cd accel-ppp/tests && - sudo python3 -m pytest -Wall -v -m \"not vlan_mon_driver\"" + sudo python3 -m pytest -Wall --order-dependencies -v -m \"not vlan_mon_driver\"" - name: Display processes and dmesg after tests if: ${{ always() }} run: > @@ -174,7 +174,7 @@ jobs: timeout-minutes: 5 run: > ssh -i ssh-key -p2222 user@localhost "cd accel-ppp/tests && - sudo python3 -m pytest -Wall -v" + sudo python3 -m pytest -Wall --order-dependencies -v" - name: Display processes and dmesg after tests if: ${{ always() }} run: > @@ -200,7 +200,7 @@ jobs: - name: Install testing tools (using pip) run: > - sudo pip3 install pytest pytest-dependency || sudo pip3 install --break-system-packages pytest pytest-dependency + sudo pip3 install pytest pytest-dependency pytest-order || sudo pip3 install --break-system-packages pytest pytest-dependency pytest-order - name: Check out repository code uses: actions/checkout@v4 @@ -232,7 +232,7 @@ jobs: - name: Run tests timeout-minutes: 5 working-directory: ./tests - run: sudo python3 -m pytest -Wall -v + run: sudo python3 -m pytest -Wall --order-dependencies -v Test-in-GH-Coverage: #if: ${{ false }} # disable for now @@ -253,7 +253,7 @@ jobs: - name: Install testing tools (using pip) run: > - sudo pip3 install pytest pytest-dependency gcovr || sudo pip3 install --break-system-packages pytest pytest-dependency gcovr + sudo pip3 install pytest pytest-dependency pytest-order gcovr || sudo pip3 install --break-system-packages pytest pytest-dependency pytest-order gcovr - name: Check out repository code uses: actions/checkout@v4 @@ -286,7 +286,7 @@ jobs: - name: Run tests (for coverage report) (fail is ok) timeout-minutes: 5 working-directory: ./tests - run: sudo python3 -m pytest -Wall -v || exit 0 + run: sudo python3 -m pytest -Wall --order-dependencies -v || exit 0 - name: Generate coverage reports (default(txt), csv, html) run: | diff --git a/tests/README.md b/tests/README.md index d062ed46..689a16d8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -6,7 +6,7 @@ These tests are done for Ubuntu and Debian distros. Please use latest stable Deb Install pytest -Using apt: `sudo apt install python3-pytest python3-pytest-dependency` or using pip: `sudo pip3 install pytest pytest-dependency`. +Using apt: `sudo apt install python3-pytest python3-pytest-dependency python3-pytest-order` or using pip: `sudo pip3 install pytest pytest-dependency pytest-order`. pytest-dependency version must be >= 0.5 (with 'scope' support) @@ -43,13 +43,13 @@ sudo insmod build/drivers/ipoe/driver/ipoe.ko ```bash # from this dir (tests) -sudo python3 -m pytest -Wall -v +sudo python3 -m pytest -Wall --order-dependencies -v ``` To skip tests related to ipoe and vlan_mon kernel modules: ```bash # from this dir (tests) -sudo python3 -m pytest -Wall -v -m "not ipoe_driver and not vlan_mon_driver" +sudo python3 -m pytest -Wall --order-dependencies -v -m "not ipoe_driver and not vlan_mon_driver" ``` ## Preparations (for coverage report) @@ -83,7 +83,7 @@ Then insert kernel modules (ipoe.ko and vlan-mon.ko) ```bash # from root dir (parent for this dir) -sudo python3 -m pytest -Wall tests -v # execute tests to collect coverage data +sudo python3 -m pytest -Wall --order-dependencies tests -v # execute tests to collect coverage data mkdir tests/report gcovr --config=tests/gcovr.conf # default report gcovr --config=tests/gcovr.conf --csv # csv report -- cgit v1.2.3