Date: Tue, 18 Jul 2017 08:44:38 +0000 (UTC) From: Ngie Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r321122 - stable/10/lib/libcam/tests Message-ID: <201707180844.v6I8ic1O040959@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Tue Jul 18 08:44:38 2017 New Revision: 321122 URL: https://svnweb.freebsd.org/changeset/base/321122 Log: MFC r319844,r319845: r319844: Add positive and negative testcases for cam_get_device(3) r319845: Remove stdlib.h #include added in r319844 A previous iteration of the tests I added in r319844 involved free(3), but that attempt didn't pan out, so I switched to stack allocated buffers instead of heap allocated ones, making the #include unnecessary. MFC with: r319844 Modified: stable/10/lib/libcam/tests/libcam_test.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libcam/tests/libcam_test.c ============================================================================== --- stable/10/lib/libcam/tests/libcam_test.c Tue Jul 18 08:35:22 2017 (r321121) +++ stable/10/lib/libcam/tests/libcam_test.c Tue Jul 18 08:44:38 2017 (r321122) @@ -58,6 +58,75 @@ cam_has_error(void) return (strlen(cam_errbuf) != 0); } +ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_NULL_path); +ATF_TC_BODY(cam_get_device_negative_test_NULL_path, tc) +{ + char parsed_dev_name[DEV_IDLEN + 1]; + int parsed_unit; + + ATF_REQUIRE_MSG(cam_get_device(NULL, parsed_dev_name, + nitems(parsed_dev_name), &parsed_unit) == -1, + "cam_get_device succeeded unexpectedly"); +} + +ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_bad_path); +ATF_TC_BODY(cam_get_device_negative_test_bad_path, tc) +{ + char parsed_dev_name[DEV_IDLEN + 1]; + int parsed_unit; + + ATF_REQUIRE_MSG(cam_get_device("1ada", parsed_dev_name, + nitems(parsed_dev_name), &parsed_unit) == -1, + "cam_get_device succeeded unexpectedly"); +} + +ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_nul_path); +ATF_TC_BODY(cam_get_device_negative_test_nul_path, tc) +{ + char parsed_dev_name[DEV_IDLEN + 1]; + int parsed_unit; + + ATF_REQUIRE_MSG(cam_get_device("", parsed_dev_name, + nitems(parsed_dev_name), &parsed_unit) == -1, + "cam_get_device succeeded unexpectedly"); +} + +ATF_TC_WITHOUT_HEAD(cam_get_device_negative_test_root); +ATF_TC_BODY(cam_get_device_negative_test_root, tc) +{ + char parsed_dev_name[DEV_IDLEN + 1]; + int parsed_unit; + + ATF_REQUIRE_MSG(cam_get_device("/", parsed_dev_name, + nitems(parsed_dev_name), &parsed_unit) == -1, + "cam_get_device succeeded unexpectedly"); +} + +ATF_TC_WITHOUT_HEAD(cam_get_device_positive_test); +ATF_TC_BODY(cam_get_device_positive_test, tc) +{ + char expected_dev_name[] = "foo"; + char parsed_dev_name[DEV_IDLEN + 1]; + int expected_unit, parsed_unit; + + expected_unit = 1; + + ATF_REQUIRE_MSG(cam_get_device("/dev/foo1", parsed_dev_name, + nitems(parsed_dev_name), &parsed_unit) == 0, + "cam_get_device failed"); + ATF_REQUIRE_STREQ(parsed_dev_name, expected_dev_name); + ATF_REQUIRE(parsed_unit == expected_unit); + + strcpy(parsed_dev_name, ""); + parsed_unit = -1; + + ATF_REQUIRE_MSG(cam_get_device("foo1", parsed_dev_name, + nitems(parsed_dev_name), &parsed_unit) == 0, + "cam_get_device failed"); + ATF_REQUIRE_STREQ(parsed_dev_name, expected_dev_name); + ATF_REQUIRE(parsed_unit == expected_unit); +} + ATF_TC(cam_open_device_negative_test_O_RDONLY); ATF_TC_HEAD(cam_open_device_negative_test_O_RDONLY, tc) { @@ -206,6 +275,11 @@ ATF_TC_BODY(cam_freeccb_negative_test_NULL, tc) ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, cam_get_device_negative_test_NULL_path); + ATF_TP_ADD_TC(tp, cam_get_device_negative_test_bad_path); + ATF_TP_ADD_TC(tp, cam_get_device_negative_test_nul_path); + ATF_TP_ADD_TC(tp, cam_get_device_negative_test_root); + ATF_TP_ADD_TC(tp, cam_get_device_positive_test); ATF_TP_ADD_TC(tp, cam_open_device_negative_test_O_RDONLY); ATF_TP_ADD_TC(tp, cam_open_device_negative_test_nonexistent); ATF_TP_ADD_TC(tp, cam_open_device_negative_test_unprivileged);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707180844.v6I8ic1O040959>