Update blake2 accelerated software tests to work after OCF refactoring.

- Lookup device drivers to test by name instead of assuming that the
  software / hardware flags will select specific drivers.
- Set the sysctl to permit software /dev/crypto requests when testing
  the accelerated software blake2 driver.

PR:		245825
Reported by:	lwhsu
Reviewed by:	cem, lwhsu
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D24540
This commit is contained in:
John Baldwin 2020-04-22 20:43:18 +00:00
parent e27a9ad8e6
commit 871eec00e2

View File

@ -74,6 +74,17 @@ initialize_constant_buffers(void)
katbuf[i] = (uint8_t)i; katbuf[i] = (uint8_t)i;
} }
static int
lookup_crid(int fd, const char *devname)
{
struct crypt_find_op find;
find.crid = -1;
strlcpy(find.name, devname, sizeof(find.name));
ATF_REQUIRE(ioctl(fd, CIOCFINDDEV, &find) != -1);
return (find.crid);
}
static int static int
get_handle_fd(void) get_handle_fd(void)
{ {
@ -124,10 +135,10 @@ do_cryptop(int fd, int ses, size_t inlen, void *out)
} }
static void static void
test_blake2b_vectors(int crid, const char *modname) test_blake2b_vectors(const char *devname, const char *modname)
{ {
uint8_t hash[BLAKE2B_OUTBYTES]; uint8_t hash[BLAKE2B_OUTBYTES];
int fd, ses; int crid, fd, ses;
size_t i; size_t i;
ATF_REQUIRE_KERNEL_MODULE(modname); ATF_REQUIRE_KERNEL_MODULE(modname);
@ -135,6 +146,7 @@ test_blake2b_vectors(int crid, const char *modname)
initialize_constant_buffers(); initialize_constant_buffers();
fd = get_handle_fd(); fd = get_handle_fd();
crid = lookup_crid(fd, devname);
ses = create_session(fd, CRYPTO_BLAKE2B, crid, key2b, sizeof(key2b)); ses = create_session(fd, CRYPTO_BLAKE2B, crid, key2b, sizeof(key2b));
for (i = 0; i < sizeof(katbuf); i++) { for (i = 0; i < sizeof(katbuf); i++) {
@ -147,10 +159,10 @@ test_blake2b_vectors(int crid, const char *modname)
} }
static void static void
test_blake2s_vectors(int crid, const char *modname) test_blake2s_vectors(const char *devname, const char *modname)
{ {
uint8_t hash[BLAKE2S_OUTBYTES]; uint8_t hash[BLAKE2S_OUTBYTES];
int fd, ses; int crid, fd, ses;
size_t i; size_t i;
ATF_REQUIRE_KERNEL_MODULE(modname); ATF_REQUIRE_KERNEL_MODULE(modname);
@ -158,6 +170,7 @@ test_blake2s_vectors(int crid, const char *modname)
initialize_constant_buffers(); initialize_constant_buffers();
fd = get_handle_fd(); fd = get_handle_fd();
crid = lookup_crid(fd, devname);
ses = create_session(fd, CRYPTO_BLAKE2S, crid, key2s, sizeof(key2s)); ses = create_session(fd, CRYPTO_BLAKE2S, crid, key2s, sizeof(key2s));
for (i = 0; i < sizeof(katbuf); i++) { for (i = 0; i < sizeof(katbuf); i++) {
@ -173,33 +186,29 @@ ATF_TC_WITHOUT_HEAD(blake2b_vectors);
ATF_TC_BODY(blake2b_vectors, tc) ATF_TC_BODY(blake2b_vectors, tc)
{ {
ATF_REQUIRE_SYSCTL_INT("kern.cryptodevallowsoft", 1); ATF_REQUIRE_SYSCTL_INT("kern.cryptodevallowsoft", 1);
test_blake2b_vectors(CRYPTO_FLAG_SOFTWARE, "nexus/cryptosoft"); test_blake2b_vectors("cryptosoft0", "nexus/cryptosoft");
} }
ATF_TC_WITHOUT_HEAD(blake2s_vectors); ATF_TC_WITHOUT_HEAD(blake2s_vectors);
ATF_TC_BODY(blake2s_vectors, tc) ATF_TC_BODY(blake2s_vectors, tc)
{ {
ATF_REQUIRE_SYSCTL_INT("kern.cryptodevallowsoft", 1); ATF_REQUIRE_SYSCTL_INT("kern.cryptodevallowsoft", 1);
test_blake2s_vectors(CRYPTO_FLAG_SOFTWARE, "nexus/cryptosoft"); test_blake2s_vectors("cryptosoft0", "nexus/cryptosoft");
} }
#if defined(__i386__) || defined(__amd64__) #if defined(__i386__) || defined(__amd64__)
ATF_TC_WITHOUT_HEAD(blake2b_vectors_x86); ATF_TC_WITHOUT_HEAD(blake2b_vectors_x86);
ATF_TC_BODY(blake2b_vectors_x86, tc) ATF_TC_BODY(blake2b_vectors_x86, tc)
{ {
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) ATF_REQUIRE_SYSCTL_INT("kern.cryptodevallowsoft", 1);
atf_tc_skip("https://bugs.freebsd.org/245825"); test_blake2b_vectors("blaketwo0", "nexus/blake2");
test_blake2b_vectors(CRYPTO_FLAG_HARDWARE, "nexus/blake2");
} }
ATF_TC_WITHOUT_HEAD(blake2s_vectors_x86); ATF_TC_WITHOUT_HEAD(blake2s_vectors_x86);
ATF_TC_BODY(blake2s_vectors_x86, tc) ATF_TC_BODY(blake2s_vectors_x86, tc)
{ {
if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false)) ATF_REQUIRE_SYSCTL_INT("kern.cryptodevallowsoft", 1);
atf_tc_skip("https://bugs.freebsd.org/245825"); test_blake2s_vectors("blaketwo0", "nexus/blake2");
test_blake2s_vectors(CRYPTO_FLAG_HARDWARE, "nexus/blake2");
} }
#endif #endif