Fix test of ses(4) when there is no SES device exists
glob(3) returns GLOB_NOMATCH if GLOB_NOCHECK or GLOB_NOMAGIC flag is not passed so ATF_REQUIRE_EQ(r, 0) will cause a precondition check failure if no /dev/ses* exists. Remove calling of atf_tc_skip() in ATF_TC_CLEANUP() because it would let the clean up procedure unfinish. While here, fix a set-but-not-used warning. Reviewed by: asomers Differential Revision: https://reviews.freebsd.org/D34056
This commit is contained in:
+17
-7
@@ -34,26 +34,36 @@ for_each_ses_dev(ses_cb cb, int oflags)
|
||||
glob_t g;
|
||||
int r;
|
||||
unsigned i;
|
||||
bool tested = false;
|
||||
|
||||
g.gl_pathc = 0;
|
||||
g.gl_pathv = NULL;
|
||||
g.gl_offs = 0;
|
||||
|
||||
r = glob("/dev/ses*", GLOB_NOSORT, NULL, &g);
|
||||
r = glob("/dev/ses*", GLOB_NOCHECK | GLOB_NOSORT, NULL, &g);
|
||||
ATF_REQUIRE_EQ(r, 0);
|
||||
if (g.gl_matchc == 0)
|
||||
return;
|
||||
|
||||
for(i = 0; i < g.gl_pathc; i++) {
|
||||
for(i = 0; i < g.gl_matchc; i++) {
|
||||
int fd;
|
||||
|
||||
fd = open(g.gl_pathv[i], oflags);
|
||||
ATF_REQUIRE(fd >= 0);
|
||||
tested |= cb(g.gl_pathv[i], fd);
|
||||
cb(g.gl_pathv[i], fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if (!tested)
|
||||
atf_tc_skip("No supported devices found");
|
||||
|
||||
globfree(&g);
|
||||
}
|
||||
|
||||
static bool
|
||||
has_ses()
|
||||
{
|
||||
glob_t g;
|
||||
int r;
|
||||
|
||||
r = glob("/dev/ses*", GLOB_NOCHECK | GLOB_NOSORT, NULL, &g);
|
||||
ATF_REQUIRE_EQ(r, 0);
|
||||
|
||||
return (g.gl_matchc != 0);
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ for_one_ses_dev(ses_cb cb)
|
||||
g.gl_pathv = NULL;
|
||||
g.gl_offs = 0;
|
||||
|
||||
r = glob("/dev/ses*", GLOB_NOSORT, NULL, &g);
|
||||
r = glob("/dev/ses*", GLOB_NOCHECK | GLOB_NOSORT, NULL, &g);
|
||||
ATF_REQUIRE_EQ(r, 0);
|
||||
if (g.gl_pathc == 0)
|
||||
atf_tc_skip("No ses devices found");
|
||||
if (g.gl_matchc == 0)
|
||||
return;
|
||||
|
||||
fd = open(g.gl_pathv[0], O_RDWR);
|
||||
ATF_REQUIRE(fd >= 0);
|
||||
@@ -84,7 +84,6 @@ static bool do_setelmstat(const char *devname __unused, int fd) {
|
||||
for (elm_idx = 0; elm_idx < nobj; elm_idx++) {
|
||||
encioc_elm_status_t elmstat;
|
||||
struct ses_ctrl_dev_slot *cslot;
|
||||
struct ses_status_dev_slot *sslot;
|
||||
|
||||
if (last_elm_type != map[elm_idx].elm_type) {
|
||||
/* skip overall elements */
|
||||
@@ -99,7 +98,6 @@ static bool do_setelmstat(const char *devname __unused, int fd) {
|
||||
ATF_REQUIRE_EQ(r, 0);
|
||||
|
||||
cslot = (struct ses_ctrl_dev_slot*)&elmstat.cstat[0];
|
||||
sslot = (struct ses_status_dev_slot*)&elmstat.cstat[0];
|
||||
|
||||
ses_ctrl_common_set_select(&cslot->common, 1);
|
||||
ses_ctrl_dev_slot_set_rqst_ident(cslot, 1);
|
||||
@@ -203,10 +201,16 @@ ATF_TC_HEAD(setelmstat, tc)
|
||||
}
|
||||
ATF_TC_BODY(setelmstat, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
|
||||
for_one_ses_dev(do_setelmstat);
|
||||
}
|
||||
ATF_TC_CLEANUP(setelmstat, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
return;
|
||||
|
||||
for_one_ses_dev(do_setelmstat_cleanup);
|
||||
}
|
||||
|
||||
@@ -262,6 +266,9 @@ ATF_TC_HEAD(setencstat, tc)
|
||||
}
|
||||
ATF_TC_BODY(setencstat, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
|
||||
for_each_ses_dev(do_setencstat, O_RDWR);
|
||||
}
|
||||
ATF_TC_CLEANUP(setencstat, tc)
|
||||
|
||||
@@ -120,6 +120,8 @@ ATF_TC_HEAD(getelmdesc, tc)
|
||||
}
|
||||
ATF_TC_BODY(getelmdesc, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getelmdesc, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -221,6 +223,8 @@ ATF_TC_HEAD(getelmdevnames, tc)
|
||||
}
|
||||
ATF_TC_BODY(getelmdevnames, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getelmdevnames, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -311,6 +315,8 @@ ATF_TC_HEAD(getelmmap, tc)
|
||||
}
|
||||
ATF_TC_BODY(getelmmap, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getelmmap, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -380,6 +386,8 @@ ATF_TC_HEAD(getelmstat, tc)
|
||||
}
|
||||
ATF_TC_BODY(getelmstat, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getelmstat, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -428,6 +436,8 @@ ATF_TC_HEAD(getencid, tc)
|
||||
}
|
||||
ATF_TC_BODY(getencid, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getencid, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -472,6 +482,8 @@ ATF_TC_HEAD(getencname, tc)
|
||||
}
|
||||
ATF_TC_BODY(getencname, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getencname, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -513,6 +525,8 @@ ATF_TC_HEAD(getencstat, tc)
|
||||
}
|
||||
ATF_TC_BODY(getencstat, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getencstat, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -559,6 +573,8 @@ ATF_TC_HEAD(getnelm, tc)
|
||||
}
|
||||
ATF_TC_BODY(getnelm, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
for_each_ses_dev(do_getnelm, O_RDONLY);
|
||||
}
|
||||
|
||||
@@ -609,6 +625,8 @@ ATF_TC_HEAD(getstring, tc)
|
||||
}
|
||||
ATF_TC_BODY(getstring, tc)
|
||||
{
|
||||
if (!has_ses())
|
||||
atf_tc_skip("No ses devices found");
|
||||
atf_tc_expect_fail("Bug 258188 ENCIO_GETSTRING does not set the string's returned size");
|
||||
for_each_ses_dev(do_getstring, O_RDWR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user