tags = ['functional', 'history']
[tests/functional/hkdf]
-tests = ['run_hkdf_test']
+pre =
+post =
+tests = ['hkdf_test']
tags = ['functional', 'hkdf']
[tests/functional/inheritance]
tags = ['functional', 'history']
[tests/functional/hkdf]
-tests = ['run_hkdf_test']
+pre =
+post =
+tests = ['hkdf_test']
tags = ['functional', 'hkdf']
[tests/functional/inuse]
/user_ns_exec
/write_dos_attributes
/xattrtest
+/zed_fd_spill-zedlet
+/suid_write_to_file
+/cp_files
+/ctime
+/truncate_test
+/ereports
+/zfs_diff-socket
+/dosmode_readonly_write
+/edonr_test
+/skein_test
+/sha2_test
threadsappend_SOURCES = threadsappend.c
threadsappend_LDADD = -lpthread
+pkgexec_PROGRAMS += suid_write_to_file
+suid_write_to_file_SOURCES = suid_write_to_file.c
+
+pkgexec_PROGRAMS += cp_files
+cp_files_SOURCES = cp_files.c
+
+pkgexec_PROGRAMS += ctime
+ctime_SOURCES = ctime.c
+
+pkgexec_PROGRAMS += truncate_test
+truncate_test_SOURCES = truncate_test.c
+
+pkgexec_PROGRAMS += ereports
+ereports_SOURCES = ereports.c
+ereports_LDADD = \
+ $(abs_top_builddir)/lib/libnvpair/libnvpair.la \
+ $(abs_top_builddir)/lib/libzfs/libzfs.la
+
+pkgexec_PROGRAMS += zfs_diff-socket
+zfs_diff_socket_SOURCES = zfs_diff-socket.c
+
+pkgexec_PROGRAMS += dosmode_readonly_write
+dosmode_readonly_write_SOURCES = dosmode_readonly_write.c
+
+
+pkgexec_PROGRAMS += edonr_test skein_test sha2_test
+skein_test_SOURCES = checksum/skein_test.c
+sha2_test_SOURCES = checksum/sha2_test.c
+edonr_test_SOURCES = checksum/edonr_test.c
+skein_test_LDADD = \
+ $(abs_top_builddir)/lib/libicp/libicp.la \
+ $(abs_top_builddir)/lib/libspl/libspl_assert.la
+sha2_test_LDADD = \
+ $(abs_top_builddir)/lib/libicp/libicp.la \
+ $(abs_top_builddir)/lib/libspl/libspl_assert.la
+edonr_test_LDADD = \
+ $(abs_top_builddir)/lib/libicp/libicp.la \
+ $(abs_top_builddir)/lib/libspl/libspl_assert.la
+
if BUILD_LINUX
pkgexec_PROGRAMS += getversion
pkgexec_PROGRAMS += xattrtest
xattrtest_SOURCES = xattrtest.c
+
+pkgexec_PROGRAMS += zed_fd_spill-zedlet
+zed_fd_spill_zedlet_SOURCES = zed_fd_spill-zedlet.c
endif
--- /dev/null
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://opensource.org/licenses/CDDL-1.0.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2013 Saso Kiselkov. All rights reserved.
+ */
+
+/*
+ * This is just to keep the compiler happy about sys/time.h not declaring
+ * gettimeofday due to -D_KERNEL (we can do this since we're actually
+ * running in userspace, but we need -D_KERNEL for the remaining Edon-R code).
+ */
+#ifdef _KERNEL
+#undef _KERNEL
+#endif
+
+#include <sys/edonr.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/stdtypes.h>
+
+/*
+ * Test messages from:
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
+ */
+const char *test_msg0 = "abc";
+const char *test_msg1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
+ "lmnomnopnopq";
+const char *test_msg2 = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
+ "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
+
+/*
+ * Test digests computed by hand. There's no formal standard or spec for edonr.
+ */
+const uint8_t edonr_224_test_digests[][28] = {
+ {
+ /* for test_msg0 */
+ 0x56, 0x63, 0xc4, 0x93, 0x95, 0x20, 0xfa, 0xf6,
+ 0x12, 0x31, 0x65, 0xa4, 0x66, 0xf2, 0x56, 0x01,
+ 0x95, 0x2e, 0xa9, 0xe4, 0x24, 0xdd, 0xc9, 0x6b,
+ 0xef, 0xd0, 0x40, 0x94
+ },
+ {
+ /* for test_msg1 */
+ 0xd0, 0x13, 0xe4, 0x87, 0x4d, 0x06, 0x8d, 0xca,
+ 0x4e, 0x14, 0xb9, 0x37, 0x2f, 0xce, 0x12, 0x20,
+ 0x60, 0xf8, 0x5c, 0x0a, 0xfd, 0x7a, 0x7d, 0x97,
+ 0x88, 0x2b, 0x05, 0x75
+ }
+ /* no test vector for test_msg2 */
+};
+
+const uint8_t edonr_256_test_digests[][32] = {
+ {
+ /* for test_msg0 */
+ 0x54, 0xd7, 0x8b, 0x13, 0xc7, 0x4e, 0xda, 0x5a,
+ 0xed, 0xc2, 0x71, 0xcc, 0x88, 0x1f, 0xb2, 0x2f,
+ 0x83, 0x99, 0xaf, 0xd3, 0x04, 0x0b, 0x6a, 0x39,
+ 0x2d, 0x73, 0x94, 0x05, 0x50, 0x8d, 0xd8, 0x51
+ },
+ {
+ /* for test_msg1 */
+ 0x49, 0x2d, 0x0b, 0x19, 0xab, 0x1e, 0xde, 0x3a,
+ 0xea, 0x9b, 0xf2, 0x39, 0x3a, 0xb1, 0x21, 0xde,
+ 0x21, 0xf6, 0x80, 0x1f, 0xad, 0xbe, 0x8b, 0x07,
+ 0xc7, 0xfb, 0xe6, 0x99, 0x0e, 0x4d, 0x73, 0x63
+ }
+ /* no test vectorfor test_msg2 */
+};
+
+const uint8_t edonr_384_test_digests[][48] = {
+ {
+ /* for test_msg0 */
+ 0x0e, 0x7c, 0xd7, 0x85, 0x78, 0x77, 0xe0, 0x89,
+ 0x5b, 0x1c, 0xdf, 0x49, 0xf4, 0x1d, 0x20, 0x9c,
+ 0x72, 0x7d, 0x2e, 0x57, 0x9b, 0x9b, 0x9a, 0xdc,
+ 0x60, 0x27, 0x97, 0x82, 0xb9, 0x90, 0x72, 0xec,
+ 0x7e, 0xce, 0xd3, 0x16, 0x5f, 0x47, 0x75, 0x48,
+ 0xfa, 0x60, 0x72, 0x7e, 0x01, 0xc7, 0x7c, 0xc6
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* for test_msg2 */
+ 0xe2, 0x34, 0xa1, 0x02, 0x83, 0x76, 0xae, 0xe6,
+ 0x82, 0xd9, 0x38, 0x32, 0x0e, 0x00, 0x78, 0xd2,
+ 0x34, 0xdb, 0xb9, 0xbd, 0xf0, 0x08, 0xa8, 0x0f,
+ 0x63, 0x1c, 0x3d, 0x4a, 0xfd, 0x0a, 0xe9, 0x59,
+ 0xdc, 0xd4, 0xce, 0xcd, 0x8d, 0x67, 0x6c, 0xea,
+ 0xbb, 0x1a, 0x32, 0xed, 0x5c, 0x6b, 0xf1, 0x7f
+ }
+};
+
+const uint8_t edonr_512_test_digests[][64] = {
+ {
+ /* for test_msg0 */
+ 0x1b, 0x14, 0xdb, 0x15, 0x5f, 0x1d, 0x40, 0x65,
+ 0x94, 0xb8, 0xce, 0xf7, 0x0a, 0x43, 0x62, 0xec,
+ 0x6b, 0x5d, 0xe6, 0xa5, 0xda, 0xf5, 0x0e, 0xc9,
+ 0x99, 0xe9, 0x87, 0xc1, 0x9d, 0x30, 0x49, 0xe2,
+ 0xde, 0x59, 0x77, 0xbb, 0x05, 0xb1, 0xbb, 0x22,
+ 0x00, 0x50, 0xa1, 0xea, 0x5b, 0x46, 0xa9, 0xf1,
+ 0x74, 0x0a, 0xca, 0xfb, 0xf6, 0xb4, 0x50, 0x32,
+ 0xad, 0xc9, 0x0c, 0x62, 0x83, 0x72, 0xc2, 0x2b
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* for test_msg2 */
+ 0x53, 0x51, 0x07, 0x0d, 0xc5, 0x1c, 0x3b, 0x2b,
+ 0xac, 0xa5, 0xa6, 0x0d, 0x02, 0x52, 0xcc, 0xb4,
+ 0xe4, 0x92, 0x1a, 0x96, 0xfe, 0x5a, 0x69, 0xe7,
+ 0x6d, 0xad, 0x48, 0xfd, 0x21, 0xa0, 0x84, 0x5a,
+ 0xd5, 0x7f, 0x88, 0x0b, 0x3e, 0x4a, 0x90, 0x7b,
+ 0xc5, 0x03, 0x15, 0x18, 0x42, 0xbb, 0x94, 0x9e,
+ 0x1c, 0xba, 0x74, 0x39, 0xa6, 0x40, 0x9a, 0x34,
+ 0xb8, 0x43, 0x6c, 0xb4, 0x69, 0x21, 0x58, 0x3c
+ }
+};
+
+int
+main(int argc, char *argv[])
+{
+ boolean_t failed = B_FALSE;
+ uint64_t cpu_mhz = 0;
+
+ if (argc == 2)
+ cpu_mhz = atoi(argv[1]);
+
+#define EDONR_ALGO_TEST(_m, mode, testdigest) \
+ do { \
+ EdonRState ctx; \
+ uint8_t digest[mode / 8]; \
+ EdonRInit(&ctx, mode); \
+ EdonRUpdate(&ctx, (const uint8_t *) _m, strlen(_m) * 8);\
+ EdonRFinal(&ctx, digest); \
+ (void) printf("Edon-R-%-6sMessage: " #_m \
+ "\tResult: ", #mode); \
+ if (memcmp(digest, testdigest, mode / 8) == 0) { \
+ (void) printf("OK\n"); \
+ } else { \
+ (void) printf("FAILED!\n"); \
+ failed = B_TRUE; \
+ } \
+ } while (0)
+
+#define EDONR_PERF_TEST(mode) \
+ do { \
+ EdonRState ctx; \
+ uint8_t digest[mode / 8]; \
+ uint8_t block[131072]; \
+ uint64_t delta; \
+ double cpb = 0; \
+ int i; \
+ struct timeval start, end; \
+ memset(block, 0, sizeof (block)); \
+ (void) gettimeofday(&start, NULL); \
+ EdonRInit(&ctx, mode); \
+ for (i = 0; i < 8192; i++) \
+ EdonRUpdate(&ctx, block, sizeof (block) * 8); \
+ EdonRFinal(&ctx, digest); \
+ (void) gettimeofday(&end, NULL); \
+ delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
+ (start.tv_sec * 1000000llu + start.tv_usec); \
+ if (cpu_mhz != 0) { \
+ cpb = (cpu_mhz * 1e6 * ((double)delta / \
+ 1000000)) / (8192 * 128 * 1024); \
+ } \
+ (void) printf("Edon-R-%-6s%llu us (%.02f CPB)\n", #mode,\
+ (u_longlong_t)delta, cpb); \
+ } while (0)
+
+ (void) printf("Running algorithm correctness tests:\n");
+ EDONR_ALGO_TEST(test_msg0, 224, edonr_224_test_digests[0]);
+ EDONR_ALGO_TEST(test_msg1, 224, edonr_224_test_digests[1]);
+ EDONR_ALGO_TEST(test_msg0, 256, edonr_256_test_digests[0]);
+ EDONR_ALGO_TEST(test_msg1, 256, edonr_256_test_digests[1]);
+ EDONR_ALGO_TEST(test_msg0, 384, edonr_384_test_digests[0]);
+ EDONR_ALGO_TEST(test_msg2, 384, edonr_384_test_digests[2]);
+ EDONR_ALGO_TEST(test_msg0, 512, edonr_512_test_digests[0]);
+ EDONR_ALGO_TEST(test_msg2, 512, edonr_512_test_digests[2]);
+ if (failed)
+ return (1);
+
+ (void) printf("Running performance tests (hashing 1024 MiB of "
+ "data):\n");
+ EDONR_PERF_TEST(256);
+ EDONR_PERF_TEST(512);
+
+ return (0);
+}
--- /dev/null
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://opensource.org/licenses/CDDL-1.0.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2013 Saso Kiselkov. All rights reserved.
+ */
+
+/*
+ * This is just to keep the compiler happy about sys/time.h not declaring
+ * gettimeofday due to -D_KERNEL (we can do this since we're actually
+ * running in userspace, but we need -D_KERNEL for the remaining SHA2 code).
+ */
+#ifdef _KERNEL
+#undef _KERNEL
+#endif
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/time.h>
+#define _SHA2_IMPL
+#include <sys/sha2.h>
+#include <sys/stdtypes.h>
+
+
+/*
+ * Test messages from:
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
+ */
+
+const char *test_msg0 = "abc";
+const char *test_msg1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
+ "lmnomnopnopq";
+const char *test_msg2 = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
+ "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
+
+/*
+ * Test digests from:
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
+ */
+const uint8_t sha256_test_digests[][32] = {
+ {
+ /* for test_msg0 */
+ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
+ 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
+ 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
+ 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD
+ },
+ {
+ /* for test_msg1 */
+ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
+ 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
+ 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
+ 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1
+ }
+ /* no test vector for test_msg2 */
+};
+
+const uint8_t sha384_test_digests[][48] = {
+ {
+ /* for test_msg0 */
+ 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
+ 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
+ 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
+ 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
+ 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
+ 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* for test_msg2 */
+ 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8,
+ 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47,
+ 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2,
+ 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12,
+ 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9,
+ 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39
+ }
+};
+
+const uint8_t sha512_test_digests[][64] = {
+ {
+ /* for test_msg0 */
+ 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA,
+ 0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31,
+ 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2,
+ 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A,
+ 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8,
+ 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD,
+ 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E,
+ 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* for test_msg2 */
+ 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA,
+ 0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F,
+ 0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1,
+ 0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18,
+ 0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4,
+ 0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A,
+ 0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54,
+ 0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09
+ }
+};
+
+const uint8_t sha512_224_test_digests[][28] = {
+ {
+ /* for test_msg0 */
+ 0x46, 0x34, 0x27, 0x0F, 0x70, 0x7B, 0x6A, 0x54,
+ 0xDA, 0xAE, 0x75, 0x30, 0x46, 0x08, 0x42, 0xE2,
+ 0x0E, 0x37, 0xED, 0x26, 0x5C, 0xEE, 0xE9, 0xA4,
+ 0x3E, 0x89, 0x24, 0xAA
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* for test_msg2 */
+ 0x23, 0xFE, 0xC5, 0xBB, 0x94, 0xD6, 0x0B, 0x23,
+ 0x30, 0x81, 0x92, 0x64, 0x0B, 0x0C, 0x45, 0x33,
+ 0x35, 0xD6, 0x64, 0x73, 0x4F, 0xE4, 0x0E, 0x72,
+ 0x68, 0x67, 0x4A, 0xF9
+ }
+};
+
+const uint8_t sha512_256_test_digests[][32] = {
+ {
+ /* for test_msg0 */
+ 0x53, 0x04, 0x8E, 0x26, 0x81, 0x94, 0x1E, 0xF9,
+ 0x9B, 0x2E, 0x29, 0xB7, 0x6B, 0x4C, 0x7D, 0xAB,
+ 0xE4, 0xC2, 0xD0, 0xC6, 0x34, 0xFC, 0x6D, 0x46,
+ 0xE0, 0xE2, 0xF1, 0x31, 0x07, 0xE7, 0xAF, 0x23
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* for test_msg2 */
+ 0x39, 0x28, 0xE1, 0x84, 0xFB, 0x86, 0x90, 0xF8,
+ 0x40, 0xDA, 0x39, 0x88, 0x12, 0x1D, 0x31, 0xBE,
+ 0x65, 0xCB, 0x9D, 0x3E, 0xF8, 0x3E, 0xE6, 0x14,
+ 0x6F, 0xEA, 0xC8, 0x61, 0xE1, 0x9B, 0x56, 0x3A
+ }
+};
+
+int
+main(int argc, char *argv[])
+{
+ boolean_t failed = B_FALSE;
+ uint64_t cpu_mhz = 0;
+
+ if (argc == 2)
+ cpu_mhz = atoi(argv[1]);
+
+#define SHA2_ALGO_TEST(_m, mode, diglen, testdigest) \
+ do { \
+ SHA2_CTX ctx; \
+ uint8_t digest[diglen / 8]; \
+ SHA2Init(SHA ## mode ## _MECH_INFO_TYPE, &ctx); \
+ SHA2Update(&ctx, _m, strlen(_m)); \
+ SHA2Final(digest, &ctx); \
+ (void) printf("SHA%-9sMessage: " #_m \
+ "\tResult: ", #mode); \
+ if (memcmp(digest, testdigest, diglen / 8) == 0) { \
+ (void) printf("OK\n"); \
+ } else { \
+ (void) printf("FAILED!\n"); \
+ failed = B_TRUE; \
+ } \
+ } while (0)
+
+#define SHA2_PERF_TEST(mode, diglen) \
+ do { \
+ SHA2_CTX ctx; \
+ uint8_t digest[diglen / 8]; \
+ uint8_t block[131072]; \
+ uint64_t delta; \
+ double cpb = 0; \
+ int i; \
+ struct timeval start, end; \
+ memset(block, 0, sizeof (block)); \
+ (void) gettimeofday(&start, NULL); \
+ SHA2Init(SHA ## mode ## _MECH_INFO_TYPE, &ctx); \
+ for (i = 0; i < 8192; i++) \
+ SHA2Update(&ctx, block, sizeof (block)); \
+ SHA2Final(digest, &ctx); \
+ (void) gettimeofday(&end, NULL); \
+ delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
+ (start.tv_sec * 1000000llu + start.tv_usec); \
+ if (cpu_mhz != 0) { \
+ cpb = (cpu_mhz * 1e6 * ((double)delta / \
+ 1000000)) / (8192 * 128 * 1024); \
+ } \
+ (void) printf("SHA%-9s%llu us (%.02f CPB)\n", #mode, \
+ (u_longlong_t)delta, cpb); \
+ } while (0)
+
+ (void) printf("Running algorithm correctness tests:\n");
+ SHA2_ALGO_TEST(test_msg0, 256, 256, sha256_test_digests[0]);
+ SHA2_ALGO_TEST(test_msg1, 256, 256, sha256_test_digests[1]);
+ SHA2_ALGO_TEST(test_msg0, 384, 384, sha384_test_digests[0]);
+ SHA2_ALGO_TEST(test_msg2, 384, 384, sha384_test_digests[2]);
+ SHA2_ALGO_TEST(test_msg0, 512, 512, sha512_test_digests[0]);
+ SHA2_ALGO_TEST(test_msg2, 512, 512, sha512_test_digests[2]);
+ SHA2_ALGO_TEST(test_msg0, 512_224, 224, sha512_224_test_digests[0]);
+ SHA2_ALGO_TEST(test_msg2, 512_224, 224, sha512_224_test_digests[2]);
+ SHA2_ALGO_TEST(test_msg0, 512_256, 256, sha512_256_test_digests[0]);
+ SHA2_ALGO_TEST(test_msg2, 512_256, 256, sha512_256_test_digests[2]);
+
+ if (failed)
+ return (1);
+
+ (void) printf("Running performance tests (hashing 1024 MiB of "
+ "data):\n");
+ SHA2_PERF_TEST(256, 256);
+ SHA2_PERF_TEST(512, 512);
+
+ return (0);
+}
--- /dev/null
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://opensource.org/licenses/CDDL-1.0.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2013 Saso Kiselkov. All rights reserved.
+ */
+
+/*
+ * This is just to keep the compiler happy about sys/time.h not declaring
+ * gettimeofday due to -D_KERNEL (we can do this since we're actually
+ * running in userspace, but we need -D_KERNEL for the remaining Skein code).
+ */
+#ifdef _KERNEL
+#undef _KERNEL
+#endif
+
+#include <sys/skein.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/stdtypes.h>
+
+/*
+ * Skein test suite using values from the Skein V1.3 specification found at:
+ * http://www.skein-hash.info/sites/default/files/skein1.3.pdf
+ */
+
+/*
+ * Test messages from the Skein spec, Appendix C.
+ */
+const uint8_t test_msg0[] = {
+ 0xFF
+};
+
+const uint8_t test_msg1[] = {
+ 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
+ 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
+ 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
+ 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0
+};
+
+const uint8_t test_msg2[] = {
+ 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
+ 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
+ 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
+ 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
+ 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
+ 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
+ 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
+ 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0
+};
+
+const uint8_t test_msg3[] = {
+ 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
+ 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
+ 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
+ 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
+ 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
+ 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
+ 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
+ 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0,
+ 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8,
+ 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0,
+ 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8,
+ 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0,
+ 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98,
+ 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
+ 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88,
+ 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80
+};
+
+const uint8_t test_msg4[] = {
+ 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
+ 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
+ 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
+ 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
+ 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
+ 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
+ 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
+ 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0,
+ 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8,
+ 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0,
+ 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8,
+ 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0,
+ 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98,
+ 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
+ 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88,
+ 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80,
+ 0x7F, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78,
+ 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70,
+ 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68,
+ 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x60,
+ 0x5F, 0x5E, 0x5D, 0x5C, 0x5B, 0x5A, 0x59, 0x58,
+ 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51, 0x50,
+ 0x4F, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, 0x49, 0x48,
+ 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x40,
+ 0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38,
+ 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30,
+ 0x2F, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x28,
+ 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20,
+ 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
+ 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
+ 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
+ 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00
+};
+
+/*
+ * Test digests from the Skein spec, Appendix C.
+ */
+const uint8_t skein_256_test_digests[][32] = {
+ {
+ /* for test_msg0 */
+ 0x0B, 0x98, 0xDC, 0xD1, 0x98, 0xEA, 0x0E, 0x50,
+ 0xA7, 0xA2, 0x44, 0xC4, 0x44, 0xE2, 0x5C, 0x23,
+ 0xDA, 0x30, 0xC1, 0x0F, 0xC9, 0xA1, 0xF2, 0x70,
+ 0xA6, 0x63, 0x7F, 0x1F, 0x34, 0xE6, 0x7E, 0xD2
+ },
+ {
+ /* for test_msg1 */
+ 0x8D, 0x0F, 0xA4, 0xEF, 0x77, 0x7F, 0xD7, 0x59,
+ 0xDF, 0xD4, 0x04, 0x4E, 0x6F, 0x6A, 0x5A, 0xC3,
+ 0xC7, 0x74, 0xAE, 0xC9, 0x43, 0xDC, 0xFC, 0x07,
+ 0x92, 0x7B, 0x72, 0x3B, 0x5D, 0xBF, 0x40, 0x8B
+ },
+ {
+ /* for test_msg2 */
+ 0xDF, 0x28, 0xE9, 0x16, 0x63, 0x0D, 0x0B, 0x44,
+ 0xC4, 0xA8, 0x49, 0xDC, 0x9A, 0x02, 0xF0, 0x7A,
+ 0x07, 0xCB, 0x30, 0xF7, 0x32, 0x31, 0x82, 0x56,
+ 0xB1, 0x5D, 0x86, 0x5A, 0xC4, 0xAE, 0x16, 0x2F
+ }
+ /* no test digests for test_msg3 and test_msg4 */
+};
+
+const uint8_t skein_512_test_digests[][64] = {
+ {
+ /* for test_msg0 */
+ 0x71, 0xB7, 0xBC, 0xE6, 0xFE, 0x64, 0x52, 0x22,
+ 0x7B, 0x9C, 0xED, 0x60, 0x14, 0x24, 0x9E, 0x5B,
+ 0xF9, 0xA9, 0x75, 0x4C, 0x3A, 0xD6, 0x18, 0xCC,
+ 0xC4, 0xE0, 0xAA, 0xE1, 0x6B, 0x31, 0x6C, 0xC8,
+ 0xCA, 0x69, 0x8D, 0x86, 0x43, 0x07, 0xED, 0x3E,
+ 0x80, 0xB6, 0xEF, 0x15, 0x70, 0x81, 0x2A, 0xC5,
+ 0x27, 0x2D, 0xC4, 0x09, 0xB5, 0xA0, 0x12, 0xDF,
+ 0x2A, 0x57, 0x91, 0x02, 0xF3, 0x40, 0x61, 0x7A
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0,
+ },
+ {
+ /* for test_msg2 */
+ 0x45, 0x86, 0x3B, 0xA3, 0xBE, 0x0C, 0x4D, 0xFC,
+ 0x27, 0xE7, 0x5D, 0x35, 0x84, 0x96, 0xF4, 0xAC,
+ 0x9A, 0x73, 0x6A, 0x50, 0x5D, 0x93, 0x13, 0xB4,
+ 0x2B, 0x2F, 0x5E, 0xAD, 0xA7, 0x9F, 0xC1, 0x7F,
+ 0x63, 0x86, 0x1E, 0x94, 0x7A, 0xFB, 0x1D, 0x05,
+ 0x6A, 0xA1, 0x99, 0x57, 0x5A, 0xD3, 0xF8, 0xC9,
+ 0xA3, 0xCC, 0x17, 0x80, 0xB5, 0xE5, 0xFA, 0x4C,
+ 0xAE, 0x05, 0x0E, 0x98, 0x98, 0x76, 0x62, 0x5B
+ },
+ {
+ /* for test_msg3 */
+ 0x91, 0xCC, 0xA5, 0x10, 0xC2, 0x63, 0xC4, 0xDD,
+ 0xD0, 0x10, 0x53, 0x0A, 0x33, 0x07, 0x33, 0x09,
+ 0x62, 0x86, 0x31, 0xF3, 0x08, 0x74, 0x7E, 0x1B,
+ 0xCB, 0xAA, 0x90, 0xE4, 0x51, 0xCA, 0xB9, 0x2E,
+ 0x51, 0x88, 0x08, 0x7A, 0xF4, 0x18, 0x87, 0x73,
+ 0xA3, 0x32, 0x30, 0x3E, 0x66, 0x67, 0xA7, 0xA2,
+ 0x10, 0x85, 0x6F, 0x74, 0x21, 0x39, 0x00, 0x00,
+ 0x71, 0xF4, 0x8E, 0x8B, 0xA2, 0xA5, 0xAD, 0xB7
+ }
+ /* no test digests for test_msg4 */
+};
+
+const uint8_t skein_1024_test_digests[][128] = {
+ {
+ /* for test_msg0 */
+ 0xE6, 0x2C, 0x05, 0x80, 0x2E, 0xA0, 0x15, 0x24,
+ 0x07, 0xCD, 0xD8, 0x78, 0x7F, 0xDA, 0x9E, 0x35,
+ 0x70, 0x3D, 0xE8, 0x62, 0xA4, 0xFB, 0xC1, 0x19,
+ 0xCF, 0xF8, 0x59, 0x0A, 0xFE, 0x79, 0x25, 0x0B,
+ 0xCC, 0xC8, 0xB3, 0xFA, 0xF1, 0xBD, 0x24, 0x22,
+ 0xAB, 0x5C, 0x0D, 0x26, 0x3F, 0xB2, 0xF8, 0xAF,
+ 0xB3, 0xF7, 0x96, 0xF0, 0x48, 0x00, 0x03, 0x81,
+ 0x53, 0x1B, 0x6F, 0x00, 0xD8, 0x51, 0x61, 0xBC,
+ 0x0F, 0xFF, 0x4B, 0xEF, 0x24, 0x86, 0xB1, 0xEB,
+ 0xCD, 0x37, 0x73, 0xFA, 0xBF, 0x50, 0xAD, 0x4A,
+ 0xD5, 0x63, 0x9A, 0xF9, 0x04, 0x0E, 0x3F, 0x29,
+ 0xC6, 0xC9, 0x31, 0x30, 0x1B, 0xF7, 0x98, 0x32,
+ 0xE9, 0xDA, 0x09, 0x85, 0x7E, 0x83, 0x1E, 0x82,
+ 0xEF, 0x8B, 0x46, 0x91, 0xC2, 0x35, 0x65, 0x65,
+ 0x15, 0xD4, 0x37, 0xD2, 0xBD, 0xA3, 0x3B, 0xCE,
+ 0xC0, 0x01, 0xC6, 0x7F, 0xFD, 0xE1, 0x5B, 0xA8
+ },
+ {
+ /* no test vector for test_msg1 */
+ 0
+ },
+ {
+ /* no test vector for test_msg2 */
+ 0
+ },
+ {
+ /* for test_msg3 */
+ 0x1F, 0x3E, 0x02, 0xC4, 0x6F, 0xB8, 0x0A, 0x3F,
+ 0xCD, 0x2D, 0xFB, 0xBC, 0x7C, 0x17, 0x38, 0x00,
+ 0xB4, 0x0C, 0x60, 0xC2, 0x35, 0x4A, 0xF5, 0x51,
+ 0x18, 0x9E, 0xBF, 0x43, 0x3C, 0x3D, 0x85, 0xF9,
+ 0xFF, 0x18, 0x03, 0xE6, 0xD9, 0x20, 0x49, 0x31,
+ 0x79, 0xED, 0x7A, 0xE7, 0xFC, 0xE6, 0x9C, 0x35,
+ 0x81, 0xA5, 0xA2, 0xF8, 0x2D, 0x3E, 0x0C, 0x7A,
+ 0x29, 0x55, 0x74, 0xD0, 0xCD, 0x7D, 0x21, 0x7C,
+ 0x48, 0x4D, 0x2F, 0x63, 0x13, 0xD5, 0x9A, 0x77,
+ 0x18, 0xEA, 0xD0, 0x7D, 0x07, 0x29, 0xC2, 0x48,
+ 0x51, 0xD7, 0xE7, 0xD2, 0x49, 0x1B, 0x90, 0x2D,
+ 0x48, 0x91, 0x94, 0xE6, 0xB7, 0xD3, 0x69, 0xDB,
+ 0x0A, 0xB7, 0xAA, 0x10, 0x6F, 0x0E, 0xE0, 0xA3,
+ 0x9A, 0x42, 0xEF, 0xC5, 0x4F, 0x18, 0xD9, 0x37,
+ 0x76, 0x08, 0x09, 0x85, 0xF9, 0x07, 0x57, 0x4F,
+ 0x99, 0x5E, 0xC6, 0xA3, 0x71, 0x53, 0xA5, 0x78
+ },
+ {
+ /* for test_msg4 */
+ 0x84, 0x2A, 0x53, 0xC9, 0x9C, 0x12, 0xB0, 0xCF,
+ 0x80, 0xCF, 0x69, 0x49, 0x1B, 0xE5, 0xE2, 0xF7,
+ 0x51, 0x5D, 0xE8, 0x73, 0x3B, 0x6E, 0xA9, 0x42,
+ 0x2D, 0xFD, 0x67, 0x66, 0x65, 0xB5, 0xFA, 0x42,
+ 0xFF, 0xB3, 0xA9, 0xC4, 0x8C, 0x21, 0x77, 0x77,
+ 0x95, 0x08, 0x48, 0xCE, 0xCD, 0xB4, 0x8F, 0x64,
+ 0x0F, 0x81, 0xFB, 0x92, 0xBE, 0xF6, 0xF8, 0x8F,
+ 0x7A, 0x85, 0xC1, 0xF7, 0xCD, 0x14, 0x46, 0xC9,
+ 0x16, 0x1C, 0x0A, 0xFE, 0x8F, 0x25, 0xAE, 0x44,
+ 0x4F, 0x40, 0xD3, 0x68, 0x00, 0x81, 0xC3, 0x5A,
+ 0xA4, 0x3F, 0x64, 0x0F, 0xD5, 0xFA, 0x3C, 0x3C,
+ 0x03, 0x0B, 0xCC, 0x06, 0xAB, 0xAC, 0x01, 0xD0,
+ 0x98, 0xBC, 0xC9, 0x84, 0xEB, 0xD8, 0x32, 0x27,
+ 0x12, 0x92, 0x1E, 0x00, 0xB1, 0xBA, 0x07, 0xD6,
+ 0xD0, 0x1F, 0x26, 0x90, 0x70, 0x50, 0x25, 0x5E,
+ 0xF2, 0xC8, 0xE2, 0x4F, 0x71, 0x6C, 0x52, 0xA5
+ }
+};
+
+int
+main(int argc, char *argv[])
+{
+ boolean_t failed = B_FALSE;
+ uint64_t cpu_mhz = 0;
+
+ if (argc == 2)
+ cpu_mhz = atoi(argv[1]);
+
+#define SKEIN_ALGO_TEST(_m, mode, diglen, testdigest) \
+ do { \
+ Skein ## mode ## _Ctxt_t ctx; \
+ uint8_t digest[diglen / 8]; \
+ (void) Skein ## mode ## _Init(&ctx, diglen); \
+ (void) Skein ## mode ## _Update(&ctx, _m, sizeof (_m)); \
+ (void) Skein ## mode ## _Final(&ctx, digest); \
+ (void) printf("Skein" #mode "/" #diglen \
+ "\tMessage: " #_m "\tResult: "); \
+ if (memcmp(digest, testdigest, diglen / 8) == 0) { \
+ (void) printf("OK\n"); \
+ } else { \
+ (void) printf("FAILED!\n"); \
+ failed = B_TRUE; \
+ } \
+ } while (0)
+
+#define SKEIN_PERF_TEST(mode, diglen) \
+ do { \
+ Skein ## mode ## _Ctxt_t ctx; \
+ uint8_t digest[diglen / 8]; \
+ uint8_t block[131072]; \
+ uint64_t delta; \
+ double cpb = 0; \
+ int i; \
+ struct timeval start, end; \
+ memset(block, 0, sizeof (block)); \
+ (void) gettimeofday(&start, NULL); \
+ (void) Skein ## mode ## _Init(&ctx, diglen); \
+ for (i = 0; i < 8192; i++) { \
+ (void) Skein ## mode ## _Update(&ctx, block, \
+ sizeof (block)); \
+ } \
+ (void) Skein ## mode ## _Final(&ctx, digest); \
+ (void) gettimeofday(&end, NULL); \
+ delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
+ (start.tv_sec * 1000000llu + start.tv_usec); \
+ if (cpu_mhz != 0) { \
+ cpb = (cpu_mhz * 1e6 * ((double)delta / \
+ 1000000)) / (8192 * 128 * 1024); \
+ } \
+ (void) printf("Skein" #mode "/" #diglen "\t%llu us " \
+ "(%.02f CPB)\n", (u_longlong_t)delta, cpb); \
+ } while (0)
+
+ (void) printf("Running algorithm correctness tests:\n");
+ SKEIN_ALGO_TEST(test_msg0, _256, 256, skein_256_test_digests[0]);
+ SKEIN_ALGO_TEST(test_msg1, _256, 256, skein_256_test_digests[1]);
+ SKEIN_ALGO_TEST(test_msg2, _256, 256, skein_256_test_digests[2]);
+ SKEIN_ALGO_TEST(test_msg0, _512, 512, skein_512_test_digests[0]);
+ SKEIN_ALGO_TEST(test_msg2, _512, 512, skein_512_test_digests[2]);
+ SKEIN_ALGO_TEST(test_msg3, _512, 512, skein_512_test_digests[3]);
+ SKEIN_ALGO_TEST(test_msg0, 1024, 1024, skein_1024_test_digests[0]);
+ SKEIN_ALGO_TEST(test_msg3, 1024, 1024, skein_1024_test_digests[3]);
+ SKEIN_ALGO_TEST(test_msg4, 1024, 1024, skein_1024_test_digests[4]);
+ if (failed)
+ return (1);
+
+ (void) printf("Running performance tests (hashing 1024 MiB of "
+ "data):\n");
+ SKEIN_PERF_TEST(_256, 256);
+ SKEIN_PERF_TEST(_512, 512);
+ SKEIN_PERF_TEST(1024, 1024);
+
+ return (0);
+}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+
+int
+main(int argc, char *argv[])
+{
+ int tfd;
+ DIR *sdir;
+ struct dirent *dirent;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s SRC DST\n", argv[0]);
+ exit(1);
+ }
+
+ sdir = opendir(argv[1]);
+ if (sdir == NULL) {
+ fprintf(stderr, "Failed to open %s: %s\n",
+ argv[1], strerror(errno));
+ exit(2);
+ }
+
+ tfd = open(argv[2], O_DIRECTORY);
+ if (tfd < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n",
+ argv[2], strerror(errno));
+ closedir(sdir);
+ exit(3);
+ }
+
+ while ((dirent = readdir(sdir)) != NULL) {
+ if (dirent->d_name[0] == '.' &&
+ (dirent->d_name[1] == '.' || dirent->d_name[1] == '\0'))
+ continue;
+
+ int fd = openat(tfd, dirent->d_name, O_CREAT|O_WRONLY, 0666);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to create %s/%s: %s\n",
+ argv[2], dirent->d_name, strerror(errno));
+ closedir(sdir);
+ close(tfd);
+ exit(4);
+ }
+ close(fd);
+ }
+
+ closedir(sdir);
+ close(tfd);
+
+ return (0);
+}
--- /dev/null
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifndef __FreeBSD__
+#include <sys/xattr.h>
+#endif
+#include <utime.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <string.h>
+
+#define ST_ATIME 0
+#define ST_CTIME 1
+#define ST_MTIME 2
+
+#define ALL_MODE (mode_t)(S_IRWXU|S_IRWXG|S_IRWXO)
+
+typedef struct timetest {
+ int type;
+ char *name;
+ int (*func)(const char *pfile);
+} timetest_t;
+
+static char tfile[BUFSIZ] = { 0 };
+
+/*
+ * DESCRIPTION:
+ * Verify time will be changed correctly after each operation.
+ *
+ * STRATEGY:
+ * 1. Define time test array.
+ * 2. Loop through each item in this array.
+ * 3. Verify the time is changed after each operation.
+ *
+ */
+
+static int
+get_file_time(const char *pfile, int what, time_t *ptr)
+{
+ struct stat stat_buf;
+
+ if (pfile == NULL || ptr == NULL) {
+ return (-1);
+ }
+
+ if (stat(pfile, &stat_buf) == -1) {
+ return (-1);
+ }
+
+ switch (what) {
+ case ST_ATIME:
+ *ptr = stat_buf.st_atime;
+ return (0);
+ case ST_CTIME:
+ *ptr = stat_buf.st_ctime;
+ return (0);
+ case ST_MTIME:
+ *ptr = stat_buf.st_mtime;
+ return (0);
+ default:
+ return (-1);
+ }
+}
+
+static ssize_t
+get_dirnamelen(const char *path)
+{
+ const char *end = strrchr(path, '/');
+ return (end ? end - path : -1);
+}
+
+static int
+do_read(const char *pfile)
+{
+ int fd, ret = 0;
+ char buf[BUFSIZ] = { 0 };
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ if ((fd = open(pfile, O_RDONLY, ALL_MODE)) == -1) {
+ return (-1);
+ }
+ if (read(fd, buf, sizeof (buf)) == -1) {
+ (void) fprintf(stderr, "read(%d, buf, %zd) failed with errno "
+ "%d\n", fd, sizeof (buf), errno);
+ (void) close(fd);
+ return (1);
+ }
+ (void) close(fd);
+
+ return (ret);
+}
+
+static int
+do_write(const char *pfile)
+{
+ int fd, ret = 0;
+ char buf[BUFSIZ] = "call function do_write()";
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ if ((fd = open(pfile, O_WRONLY, ALL_MODE)) == -1) {
+ return (-1);
+ }
+ if (write(fd, buf, strlen(buf)) == -1) {
+ (void) fprintf(stderr, "write(%d, buf, %d) failed with errno "
+ "%d\n", fd, (int)strlen(buf), errno);
+ (void) close(fd);
+ return (1);
+ }
+ (void) close(fd);
+
+ return (ret);
+}
+
+static int
+do_link(const char *pfile)
+{
+ int ret = 0;
+ char link_file[BUFSIZ + 16] = { 0 };
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ /*
+ * Figure out source file directory name, and create
+ * the link file in the same directory.
+ */
+ (void) snprintf(link_file, sizeof (link_file),
+ "%.*s/%s", (int)get_dirnamelen(pfile), pfile, "link_file");
+
+ if (link(pfile, link_file) == -1) {
+ (void) fprintf(stderr, "link(%s, %s) failed with errno %d\n",
+ pfile, link_file, errno);
+ return (1);
+ }
+
+ (void) unlink(link_file);
+
+ return (ret);
+}
+
+static int
+do_creat(const char *pfile)
+{
+ int fd, ret = 0;
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ if ((fd = creat(pfile, ALL_MODE)) == -1) {
+ (void) fprintf(stderr, "creat(%s, ALL_MODE) failed with errno "
+ "%d\n", pfile, errno);
+ return (1);
+ }
+ (void) close(fd);
+
+ return (ret);
+}
+
+static int
+do_utime(const char *pfile)
+{
+ int ret = 0;
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ /*
+ * Times of the file are set to the current time
+ */
+ if (utime(pfile, NULL) == -1) {
+ (void) fprintf(stderr, "utime(%s, NULL) failed with errno "
+ "%d\n", pfile, errno);
+ return (1);
+ }
+
+ return (ret);
+}
+
+static int
+do_chmod(const char *pfile)
+{
+ int ret = 0;
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ if (chmod(pfile, ALL_MODE) == -1) {
+ (void) fprintf(stderr, "chmod(%s, ALL_MODE) failed with "
+ "errno %d\n", pfile, errno);
+ return (1);
+ }
+
+ return (ret);
+}
+
+static int
+do_chown(const char *pfile)
+{
+ int ret = 0;
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ if (chown(pfile, getuid(), getgid()) == -1) {
+ (void) fprintf(stderr, "chown(%s, %d, %d) failed with errno "
+ "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
+ return (1);
+ }
+
+ return (ret);
+}
+
+#ifndef __FreeBSD__
+static int
+do_xattr(const char *pfile)
+{
+ int ret = 0;
+ char *value = "user.value";
+
+ if (pfile == NULL) {
+ return (-1);
+ }
+
+ if (setxattr(pfile, "user.x", value, strlen(value), 0) == -1) {
+ (void) fprintf(stderr, "setxattr(%s, %d, %d) failed with errno "
+ "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
+ return (1);
+ }
+ return (ret);
+}
+#endif
+
+static void
+cleanup(void)
+{
+ if ((strlen(tfile) != 0) && (access(tfile, F_OK) == 0)) {
+ (void) unlink(tfile);
+ }
+}
+
+static timetest_t timetest_table[] = {
+ { ST_ATIME, "st_atime", do_read },
+ { ST_ATIME, "st_atime", do_utime },
+ { ST_MTIME, "st_mtime", do_creat },
+ { ST_MTIME, "st_mtime", do_write },
+ { ST_MTIME, "st_mtime", do_utime },
+ { ST_CTIME, "st_ctime", do_creat },
+ { ST_CTIME, "st_ctime", do_write },
+ { ST_CTIME, "st_ctime", do_chmod },
+ { ST_CTIME, "st_ctime", do_chown },
+ { ST_CTIME, "st_ctime", do_link },
+ { ST_CTIME, "st_ctime", do_utime },
+#ifndef __FreeBSD__
+ { ST_CTIME, "st_ctime", do_xattr },
+#endif
+};
+
+#define NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0]))
+
+int
+main(void)
+{
+ int i, ret, fd;
+ char *penv[] = {"TESTDIR", "TESTFILE0"};
+
+ (void) atexit(cleanup);
+
+ /*
+ * Get the environment variable values.
+ */
+ for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
+ if ((penv[i] = getenv(penv[i])) == NULL) {
+ (void) fprintf(stderr, "getenv(penv[%d])\n", i);
+ return (1);
+ }
+ }
+ (void) snprintf(tfile, sizeof (tfile), "%s/%s", penv[0], penv[1]);
+
+ /*
+ * If the test file exists, remove it first.
+ */
+ if (access(tfile, F_OK) == 0) {
+ (void) unlink(tfile);
+ }
+ ret = 0;
+ if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
+ (void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
+ return (1);
+ }
+ (void) close(fd);
+
+ for (i = 0; i < NCOMMAND; i++) {
+ time_t t1, t2;
+
+ /*
+ * Get original time before operating.
+ */
+ ret = get_file_time(tfile, timetest_table[i].type, &t1);
+ if (ret != 0) {
+ (void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
+ tfile, timetest_table[i].type, ret);
+ return (1);
+ }
+
+ /*
+ * Sleep 2 seconds, then invoke command on given file
+ */
+ (void) sleep(2);
+ timetest_table[i].func(tfile);
+
+ /*
+ * Get time after operating.
+ */
+ ret = get_file_time(tfile, timetest_table[i].type, &t2);
+ if (ret != 0) {
+ (void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
+ tfile, timetest_table[i].type, ret);
+ return (1);
+ }
+
+ if (t1 == t2) {
+ (void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
+ timetest_table[i].name, (long)t1, (long)t2);
+ return (1);
+ } else {
+ (void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
+ timetest_table[i].name, (long)t1, (long)t2);
+ }
+ }
+
+ return (0);
+}
--- /dev/null
+/*
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 iXsystems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Test for correct behavior of DOS mode READONLY flag on a file.
+ * We should be able to open a file RW, set READONLY, and still write to the fd.
+ */
+
+#include <sys/stat.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef __linux__
+#include <stdint.h>
+#include <sys/fs/zfs.h>
+#endif
+
+int
+main(int argc, const char *argv[])
+{
+ const char *buf = "We should be allowed to write this to the fd.\n";
+ const char *path;
+ int fd;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s PATH\n", argv[0]);
+ return (EXIT_FAILURE);
+ }
+ path = argv[1];
+ fd = open(path, O_CREAT|O_RDWR, 0777);
+ if (fd == -1)
+ err(EXIT_FAILURE, "%s: open failed", path);
+#ifdef __linux__
+ uint64_t dosflags = ZFS_READONLY;
+ if (ioctl(fd, ZFS_IOC_SETDOSFLAGS, &dosflags) == -1)
+ err(EXIT_FAILURE, "%s: ZFS_IOC_SETDOSFLAGS failed", path);
+#else
+ if (chflags(path, UF_READONLY) == -1)
+ err(EXIT_FAILURE, "%s: chflags failed", path);
+#endif
+ if (write(fd, buf, strlen(buf)) == -1)
+ err(EXIT_FAILURE, "%s: write failed", path);
+ if (close(fd) == -1)
+ err(EXIT_FAILURE, "%s: close failed", path);
+ return (EXIT_SUCCESS);
+}
--- /dev/null
+/*
+ * CDDL HEADER START
+ *
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2020 by Delphix. All rights reserved.
+ */
+
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <libzfs.h>
+#include <sys/zfs_ioctl.h>
+#include <sys/nvpair.h>
+#include <sys/fm/protocol.h>
+#include <sys/fm/fs/zfs.h>
+
+/*
+ * Command to output io and checksum ereport values, one per line.
+ * Used by zpool_events_duplicates.ksh to check for duplicate events.
+ *
+ * example output line:
+ *
+ * checksum "error_pool" 0x856dd01ce52e336 0x000034 0x000400 0x000a402c00
+ * 0x000004 0x000000 0x000000 0x000000 0x000001
+ */
+
+/*
+ * Our ereport duplicate criteria
+ *
+ * When the class and all of these values match, then an ereport is
+ * considered to be a duplicate.
+ */
+static const char *const criteria_name[] = {
+ FM_EREPORT_PAYLOAD_ZFS_POOL,
+ FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_PRIORITY,
+
+ /* logical zio criteriai (optional) */
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
+ FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
+};
+
+#define CRITERIA_NAMES_COUNT ARRAY_SIZE(criteria_name)
+
+static void
+print_ereport_line(nvlist_t *nvl)
+{
+ char *class;
+ int last = CRITERIA_NAMES_COUNT - 1;
+
+ /*
+ * For the test case context, we only want to see 'io' and
+ * 'checksum' subclass. We skip 'data' to minimize the output.
+ */
+ if (nvlist_lookup_string(nvl, FM_CLASS, &class) != 0 ||
+ strstr(class, "ereport.fs.zfs.") == NULL ||
+ strcmp(class, "ereport.fs.zfs.data") == 0) {
+ return;
+ }
+
+ (void) printf("%s\t", class + strlen("ereport.fs.zfs."));
+
+ for (int i = 0; i < CRITERIA_NAMES_COUNT; i++) {
+ nvpair_t *nvp;
+ uint32_t i32 = 0;
+ uint64_t i64 = 0;
+ char *str = NULL;
+
+ if (nvlist_lookup_nvpair(nvl, criteria_name[i], &nvp) != 0) {
+ /* print a proxy for optional criteria */
+ (void) printf("--------");
+ (void) printf("%c", i == last ? '\n' : '\t');
+ continue;
+ }
+
+ switch (nvpair_type(nvp)) {
+ case DATA_TYPE_STRING:
+ (void) nvpair_value_string(nvp, &str);
+ (void) printf("\"%s\"", str ? str : "<NULL>");
+ break;
+
+ case DATA_TYPE_INT32:
+ (void) nvpair_value_int32(nvp, (void *)&i32);
+ (void) printf("0x%06x", i32);
+ break;
+
+ case DATA_TYPE_UINT32:
+ (void) nvpair_value_uint32(nvp, &i32);
+ (void) printf("0x%06x", i32);
+ break;
+
+ case DATA_TYPE_INT64:
+ (void) nvpair_value_int64(nvp, (void *)&i64);
+ (void) printf("0x%06llx", (u_longlong_t)i64);
+ break;
+
+ case DATA_TYPE_UINT64:
+ (void) nvpair_value_uint64(nvp, &i64);
+ if (strcmp(FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
+ criteria_name[i]) == 0)
+ (void) printf("0x%010llx", (u_longlong_t)i64);
+ else
+ (void) printf("0x%06llx", (u_longlong_t)i64);
+ break;
+ default:
+ (void) printf("<unknown>");
+ break;
+ }
+ (void) printf("%c", i == last ? '\n' : '\t');
+ }
+}
+
+static void
+ereports_dump(libzfs_handle_t *zhdl, int zevent_fd)
+{
+ nvlist_t *nvl;
+ int ret, dropped;
+
+ while (1) {
+ ret = zpool_events_next(zhdl, &nvl, &dropped, ZEVENT_NONBLOCK,
+ zevent_fd);
+ if (ret || nvl == NULL)
+ break;
+ if (dropped > 0)
+ (void) fprintf(stdout, "dropped %d events\n", dropped);
+ print_ereport_line(nvl);
+ (void) fflush(stdout);
+ nvlist_free(nvl);
+ }
+}
+
+int
+main(void)
+{
+ libzfs_handle_t *hdl;
+ int fd;
+
+ hdl = libzfs_init();
+ if (hdl == NULL) {
+ (void) fprintf(stderr, "libzfs_init: %s\n", strerror(errno));
+ exit(2);
+ }
+ fd = open(ZFS_DEV, O_RDWR);
+ if (fd < 0) {
+ (void) fprintf(stderr, "open: %s\n", strerror(errno));
+ libzfs_fini(hdl);
+ exit(2);
+ }
+
+ ereports_dump(hdl, fd);
+
+ (void) close(fd);
+ libzfs_fini(hdl);
+
+ return (0);
+}
--- /dev/null
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdbool.h>
+
+int
+main(int argc, char *argv[])
+{
+ const char *name, *phase;
+ mode_t extra;
+ struct stat st;
+
+ if (argc < 3) {
+ fprintf(stderr, "Invalid argc\n");
+ exit(1);
+ }
+
+ name = argv[1];
+ if (strcmp(name, "SUID") == 0) {
+ extra = S_ISUID;
+ } else if (strcmp(name, "SGID") == 0) {
+ extra = S_ISGID;
+ } else if (strcmp(name, "SUID_SGID") == 0) {
+ extra = S_ISUID | S_ISGID;
+ } else if (strcmp(name, "NONE") == 0) {
+ extra = 0;
+ } else {
+ fprintf(stderr, "Invalid name %s\n", name);
+ exit(1);
+ }
+
+ const char *testdir = getenv("TESTDIR");
+ if (!testdir) {
+ fprintf(stderr, "getenv(TESTDIR)\n");
+ exit(1);
+ }
+
+ umask(0);
+ if (stat(testdir, &st) == -1 && mkdir(testdir, 0777) == -1) {
+ perror("mkdir");
+ exit(2);
+ }
+
+ char fpath[1024];
+ snprintf(fpath, sizeof (fpath), "%s/%s", testdir, name);
+
+
+ phase = argv[2];
+ if (strcmp(phase, "PRECRASH") == 0) {
+
+ /* clean up last run */
+ unlink(fpath);
+ if (stat(fpath, &st) == 0) {
+ fprintf(stderr, "%s exists\n", fpath);
+ exit(3);
+ }
+
+ int fd;
+
+ fd = creat(fpath, 0777 | extra);
+ if (fd == -1) {
+ perror("creat");
+ exit(4);
+ }
+ close(fd);
+
+ if (setuid(65534) == -1) {
+ perror("setuid");
+ exit(5);
+ }
+
+ fd = open(fpath, O_RDWR);
+ if (fd == -1) {
+ perror("open");
+ exit(6);
+ }
+
+ const char buf[] = "test";
+ if (write(fd, buf, sizeof (buf)) == -1) {
+ perror("write");
+ exit(7);
+ }
+ close(fd);
+
+ } else if (strcmp(phase, "REPLAY") == 0) {
+ /* created in PRECRASH run */
+ } else {
+ fprintf(stderr, "Invalid phase %s\n", phase);
+ exit(1);
+ }
+
+ if (stat(fpath, &st) == -1) {
+ perror("stat");
+ exit(8);
+ }
+
+ /* Verify SUID/SGID are dropped */
+ mode_t res = st.st_mode & (0777 | S_ISUID | S_ISGID);
+ if (res != 0777) {
+ fprintf(stderr, "stat(2) %o\n", res);
+ exit(9);
+ }
+
+ return (0);
+}
--- /dev/null
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
+ * Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+ */
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define FSIZE 256*1024*1024
+
+static long fsize = FSIZE;
+static int errflag = 0;
+static char *filename = NULL;
+static int ftruncflag = 0;
+
+static void parse_options(int argc, char *argv[]);
+
+static void
+usage(char *execname)
+{
+ (void) fprintf(stderr,
+ "usage: %s [-s filesize] [-f] /path/to/file\n", execname);
+ (void) exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int fd;
+
+ parse_options(argc, argv);
+
+ if (ftruncflag) {
+ fd = open(filename, O_RDWR|O_CREAT, 0666);
+ if (fd < 0) {
+ perror("open");
+ return (1);
+ }
+ if (ftruncate(fd, fsize) < 0) {
+ perror("ftruncate");
+ return (1);
+ }
+ if (close(fd)) {
+ perror("close");
+ return (1);
+ }
+ } else {
+ if (truncate(filename, fsize) < 0) {
+ perror("truncate");
+ return (1);
+ }
+ }
+ return (0);
+}
+
+static void
+parse_options(int argc, char *argv[])
+{
+ int c;
+ extern char *optarg;
+ extern int optind, optopt;
+
+ while ((c = getopt(argc, argv, "s:f")) != -1) {
+ switch (c) {
+ case 's':
+ fsize = atoi(optarg);
+ break;
+ case 'f':
+ ftruncflag++;
+ break;
+ case ':':
+ (void) fprintf(stderr,
+ "Option -%c requires an operand\n", optopt);
+ errflag++;
+ break;
+ }
+ if (errflag) {
+ (void) usage(argv[0]);
+ }
+ }
+
+ if (argc <= optind) {
+ (void) fprintf(stderr, "No filename specified\n");
+ usage(argv[0]);
+ }
+ filename = argv[optind];
+}
--- /dev/null
+/*
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+int main(void) {
+ if (fork()) {
+ int err;
+ wait(&err);
+ return (err);
+ }
+
+ char buf[64];
+ sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid());
+ dup2(creat(buf, 0644), STDOUT_FILENO);
+
+ snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid());
+ execlp("ls", "ls", buf, NULL);
+ _exit(127);
+}
--- /dev/null
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+ */
+
+#include <fcntl.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct sockaddr_un sock;
+ int fd;
+ char *path;
+ size_t size;
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]);
+ exit(1);
+ }
+ path = argv[1];
+ size = sizeof (sock.sun_path);
+ strncpy(sock.sun_path, (char *)path, size - 1);
+ sock.sun_path[size - 1] = '\0';
+
+ sock.sun_family = AF_UNIX;
+ if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
+ perror("socket");
+ return (1);
+ }
+ if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) {
+ perror("bind");
+ return (1);
+ }
+ if (close(fd)) {
+ perror("close");
+ return (1);
+ }
+ return (0);
+}
user_ns_exec
write_dos_attributes
xattrtest
- stride_dd'
+ stride_dd
+ zed_fd_spill-zedlet
+ suid_write_to_file
+ cp_files
+ edonr_test
+ skein_test
+ sha2_test
+ ctime
+ truncate_test
+ ereports
+ zfs_diff-socket
+ dosmode_readonly_write'
+++ /dev/null
-/dosmode_readonly_write
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/acl/off
dist_pkgdata_SCRIPTS = \
posixmode.ksh \
cleanup.ksh \
setup.ksh
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/acl/off
-
-pkgexec_PROGRAMS = dosmode_readonly_write
-dosmode_readonly_write_SOURCES = dosmode_readonly_write.c
log_assert "Verify DOS mode flags function correctly"
log_onexit cleanup
-tests_base=$STF_SUITE/tests/functional/acl/off
testfile=$TESTDIR/testfile
owner=$ZFS_ACL_STAFF1
other=$ZFS_ACL_STAFF2
# READONLY is set. We have a special test program for that.
log_must user_run $owner touch $testfile
log_mustnot user_run $other $changeflags rdonly $testfile
-log_must user_run $owner $tests_base/dosmode_readonly_write $testfile
+log_must user_run $owner dosmode_readonly_write $testfile
log_mustnot user_run $other $changeflags nordonly $testfile
log_must hasflag rdonly $testfile
if ! is_linux; then
+++ /dev/null
-/*
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
- * Copyright (c) 2021 iXsystems, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Test for correct behavior of DOS mode READONLY flag on a file.
- * We should be able to open a file RW, set READONLY, and still write to the fd.
- */
-
-#include <sys/stat.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef __linux__
-#include <stdint.h>
-#include <sys/fs/zfs.h>
-#endif
-
-int
-main(int argc, const char *argv[])
-{
- const char *buf = "We should be allowed to write this to the fd.\n";
- const char *path;
- int fd;
-
- if (argc != 2) {
- fprintf(stderr, "usage: %s PATH\n", argv[0]);
- return (EXIT_FAILURE);
- }
- path = argv[1];
- fd = open(path, O_CREAT|O_RDWR, 0777);
- if (fd == -1)
- err(EXIT_FAILURE, "%s: open failed", path);
-#ifdef __linux__
- uint64_t dosflags = ZFS_READONLY;
- if (ioctl(fd, ZFS_IOC_SETDOSFLAGS, &dosflags) == -1)
- err(EXIT_FAILURE, "%s: ZFS_IOC_SETDOSFLAGS failed", path);
-#else
- if (chflags(path, UF_READONLY) == -1)
- err(EXIT_FAILURE, "%s: chflags failed", path);
-#endif
- if (write(fd, buf, strlen(buf)) == -1)
- err(EXIT_FAILURE, "%s: write failed", path);
- if (close(fd) == -1)
- err(EXIT_FAILURE, "%s: close failed", path);
- return (EXIT_SUCCESS);
-}
+++ /dev/null
-skein_test
-edonr_test
-sha2_test
-
-include $(top_srcdir)/config/Rules.am
-
-LDADD = \
- $(abs_top_builddir)/lib/libicp/libicp.la \
- $(abs_top_builddir)/lib/libspl/libspl_assert.la
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/checksum
dist_pkgdata_SCRIPTS = \
dist_pkgdata_DATA = \
default.cfg
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/checksum
-
-pkgexec_PROGRAMS = \
- edonr_test \
- skein_test \
- sha2_test
-
-skein_test_SOURCES = skein_test.c
-sha2_test_SOURCES = sha2_test.c
-
-edonr_test_SOURCES = edonr_test.c
+++ /dev/null
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://opensource.org/licenses/CDDL-1.0.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2013 Saso Kiselkov. All rights reserved.
- */
-
-/*
- * This is just to keep the compiler happy about sys/time.h not declaring
- * gettimeofday due to -D_KERNEL (we can do this since we're actually
- * running in userspace, but we need -D_KERNEL for the remaining Edon-R code).
- */
-#ifdef _KERNEL
-#undef _KERNEL
-#endif
-
-#include <sys/edonr.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/stdtypes.h>
-
-/*
- * Test messages from:
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
- */
-const char *test_msg0 = "abc";
-const char *test_msg1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
- "lmnomnopnopq";
-const char *test_msg2 = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
- "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
-
-/*
- * Test digests computed by hand. There's no formal standard or spec for edonr.
- */
-const uint8_t edonr_224_test_digests[][28] = {
- {
- /* for test_msg0 */
- 0x56, 0x63, 0xc4, 0x93, 0x95, 0x20, 0xfa, 0xf6,
- 0x12, 0x31, 0x65, 0xa4, 0x66, 0xf2, 0x56, 0x01,
- 0x95, 0x2e, 0xa9, 0xe4, 0x24, 0xdd, 0xc9, 0x6b,
- 0xef, 0xd0, 0x40, 0x94
- },
- {
- /* for test_msg1 */
- 0xd0, 0x13, 0xe4, 0x87, 0x4d, 0x06, 0x8d, 0xca,
- 0x4e, 0x14, 0xb9, 0x37, 0x2f, 0xce, 0x12, 0x20,
- 0x60, 0xf8, 0x5c, 0x0a, 0xfd, 0x7a, 0x7d, 0x97,
- 0x88, 0x2b, 0x05, 0x75
- }
- /* no test vector for test_msg2 */
-};
-
-const uint8_t edonr_256_test_digests[][32] = {
- {
- /* for test_msg0 */
- 0x54, 0xd7, 0x8b, 0x13, 0xc7, 0x4e, 0xda, 0x5a,
- 0xed, 0xc2, 0x71, 0xcc, 0x88, 0x1f, 0xb2, 0x2f,
- 0x83, 0x99, 0xaf, 0xd3, 0x04, 0x0b, 0x6a, 0x39,
- 0x2d, 0x73, 0x94, 0x05, 0x50, 0x8d, 0xd8, 0x51
- },
- {
- /* for test_msg1 */
- 0x49, 0x2d, 0x0b, 0x19, 0xab, 0x1e, 0xde, 0x3a,
- 0xea, 0x9b, 0xf2, 0x39, 0x3a, 0xb1, 0x21, 0xde,
- 0x21, 0xf6, 0x80, 0x1f, 0xad, 0xbe, 0x8b, 0x07,
- 0xc7, 0xfb, 0xe6, 0x99, 0x0e, 0x4d, 0x73, 0x63
- }
- /* no test vectorfor test_msg2 */
-};
-
-const uint8_t edonr_384_test_digests[][48] = {
- {
- /* for test_msg0 */
- 0x0e, 0x7c, 0xd7, 0x85, 0x78, 0x77, 0xe0, 0x89,
- 0x5b, 0x1c, 0xdf, 0x49, 0xf4, 0x1d, 0x20, 0x9c,
- 0x72, 0x7d, 0x2e, 0x57, 0x9b, 0x9b, 0x9a, 0xdc,
- 0x60, 0x27, 0x97, 0x82, 0xb9, 0x90, 0x72, 0xec,
- 0x7e, 0xce, 0xd3, 0x16, 0x5f, 0x47, 0x75, 0x48,
- 0xfa, 0x60, 0x72, 0x7e, 0x01, 0xc7, 0x7c, 0xc6
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* for test_msg2 */
- 0xe2, 0x34, 0xa1, 0x02, 0x83, 0x76, 0xae, 0xe6,
- 0x82, 0xd9, 0x38, 0x32, 0x0e, 0x00, 0x78, 0xd2,
- 0x34, 0xdb, 0xb9, 0xbd, 0xf0, 0x08, 0xa8, 0x0f,
- 0x63, 0x1c, 0x3d, 0x4a, 0xfd, 0x0a, 0xe9, 0x59,
- 0xdc, 0xd4, 0xce, 0xcd, 0x8d, 0x67, 0x6c, 0xea,
- 0xbb, 0x1a, 0x32, 0xed, 0x5c, 0x6b, 0xf1, 0x7f
- }
-};
-
-const uint8_t edonr_512_test_digests[][64] = {
- {
- /* for test_msg0 */
- 0x1b, 0x14, 0xdb, 0x15, 0x5f, 0x1d, 0x40, 0x65,
- 0x94, 0xb8, 0xce, 0xf7, 0x0a, 0x43, 0x62, 0xec,
- 0x6b, 0x5d, 0xe6, 0xa5, 0xda, 0xf5, 0x0e, 0xc9,
- 0x99, 0xe9, 0x87, 0xc1, 0x9d, 0x30, 0x49, 0xe2,
- 0xde, 0x59, 0x77, 0xbb, 0x05, 0xb1, 0xbb, 0x22,
- 0x00, 0x50, 0xa1, 0xea, 0x5b, 0x46, 0xa9, 0xf1,
- 0x74, 0x0a, 0xca, 0xfb, 0xf6, 0xb4, 0x50, 0x32,
- 0xad, 0xc9, 0x0c, 0x62, 0x83, 0x72, 0xc2, 0x2b
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* for test_msg2 */
- 0x53, 0x51, 0x07, 0x0d, 0xc5, 0x1c, 0x3b, 0x2b,
- 0xac, 0xa5, 0xa6, 0x0d, 0x02, 0x52, 0xcc, 0xb4,
- 0xe4, 0x92, 0x1a, 0x96, 0xfe, 0x5a, 0x69, 0xe7,
- 0x6d, 0xad, 0x48, 0xfd, 0x21, 0xa0, 0x84, 0x5a,
- 0xd5, 0x7f, 0x88, 0x0b, 0x3e, 0x4a, 0x90, 0x7b,
- 0xc5, 0x03, 0x15, 0x18, 0x42, 0xbb, 0x94, 0x9e,
- 0x1c, 0xba, 0x74, 0x39, 0xa6, 0x40, 0x9a, 0x34,
- 0xb8, 0x43, 0x6c, 0xb4, 0x69, 0x21, 0x58, 0x3c
- }
-};
-
-int
-main(int argc, char *argv[])
-{
- boolean_t failed = B_FALSE;
- uint64_t cpu_mhz = 0;
-
- if (argc == 2)
- cpu_mhz = atoi(argv[1]);
-
-#define EDONR_ALGO_TEST(_m, mode, testdigest) \
- do { \
- EdonRState ctx; \
- uint8_t digest[mode / 8]; \
- EdonRInit(&ctx, mode); \
- EdonRUpdate(&ctx, (const uint8_t *) _m, strlen(_m) * 8);\
- EdonRFinal(&ctx, digest); \
- (void) printf("Edon-R-%-6sMessage: " #_m \
- "\tResult: ", #mode); \
- if (memcmp(digest, testdigest, mode / 8) == 0) { \
- (void) printf("OK\n"); \
- } else { \
- (void) printf("FAILED!\n"); \
- failed = B_TRUE; \
- } \
- } while (0)
-
-#define EDONR_PERF_TEST(mode) \
- do { \
- EdonRState ctx; \
- uint8_t digest[mode / 8]; \
- uint8_t block[131072]; \
- uint64_t delta; \
- double cpb = 0; \
- int i; \
- struct timeval start, end; \
- memset(block, 0, sizeof (block)); \
- (void) gettimeofday(&start, NULL); \
- EdonRInit(&ctx, mode); \
- for (i = 0; i < 8192; i++) \
- EdonRUpdate(&ctx, block, sizeof (block) * 8); \
- EdonRFinal(&ctx, digest); \
- (void) gettimeofday(&end, NULL); \
- delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
- (start.tv_sec * 1000000llu + start.tv_usec); \
- if (cpu_mhz != 0) { \
- cpb = (cpu_mhz * 1e6 * ((double)delta / \
- 1000000)) / (8192 * 128 * 1024); \
- } \
- (void) printf("Edon-R-%-6s%llu us (%.02f CPB)\n", #mode,\
- (u_longlong_t)delta, cpb); \
- } while (0)
-
- (void) printf("Running algorithm correctness tests:\n");
- EDONR_ALGO_TEST(test_msg0, 224, edonr_224_test_digests[0]);
- EDONR_ALGO_TEST(test_msg1, 224, edonr_224_test_digests[1]);
- EDONR_ALGO_TEST(test_msg0, 256, edonr_256_test_digests[0]);
- EDONR_ALGO_TEST(test_msg1, 256, edonr_256_test_digests[1]);
- EDONR_ALGO_TEST(test_msg0, 384, edonr_384_test_digests[0]);
- EDONR_ALGO_TEST(test_msg2, 384, edonr_384_test_digests[2]);
- EDONR_ALGO_TEST(test_msg0, 512, edonr_512_test_digests[0]);
- EDONR_ALGO_TEST(test_msg2, 512, edonr_512_test_digests[2]);
- if (failed)
- return (1);
-
- (void) printf("Running performance tests (hashing 1024 MiB of "
- "data):\n");
- EDONR_PERF_TEST(256);
- EDONR_PERF_TEST(512);
-
- return (0);
-}
log_assert "Run the tests for the EdonR hash algorithm."
freq=$(get_cpu_freq)
-log_must $STF_SUITE/tests/functional/checksum/edonr_test $freq
+log_must edonr_test $freq
log_pass "EdonR tests passed."
log_assert "Run the tests for the SHA-2 hash algorithm."
freq=$(get_cpu_freq)
-log_must $STF_SUITE/tests/functional/checksum/sha2_test $freq
+log_must sha2_test $freq
log_pass "SHA-2 tests passed."
log_assert "Run the tests for the Skein hash algorithm."
freq=$(get_cpu_freq)
-log_must $STF_SUITE/tests/functional/checksum/skein_test $freq
+log_must skein_test $freq
log_pass "Skein tests passed."
+++ /dev/null
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://opensource.org/licenses/CDDL-1.0.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2013 Saso Kiselkov. All rights reserved.
- */
-
-/*
- * This is just to keep the compiler happy about sys/time.h not declaring
- * gettimeofday due to -D_KERNEL (we can do this since we're actually
- * running in userspace, but we need -D_KERNEL for the remaining SHA2 code).
- */
-#ifdef _KERNEL
-#undef _KERNEL
-#endif
-
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
-#define _SHA2_IMPL
-#include <sys/sha2.h>
-#include <sys/stdtypes.h>
-
-
-/*
- * Test messages from:
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
- */
-
-const char *test_msg0 = "abc";
-const char *test_msg1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmn"
- "lmnomnopnopq";
-const char *test_msg2 = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
- "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
-
-/*
- * Test digests from:
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
- */
-const uint8_t sha256_test_digests[][32] = {
- {
- /* for test_msg0 */
- 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
- 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
- 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
- 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD
- },
- {
- /* for test_msg1 */
- 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
- 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
- 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
- 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1
- }
- /* no test vector for test_msg2 */
-};
-
-const uint8_t sha384_test_digests[][48] = {
- {
- /* for test_msg0 */
- 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B,
- 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07,
- 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63,
- 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED,
- 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23,
- 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* for test_msg2 */
- 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8,
- 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47,
- 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2,
- 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12,
- 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9,
- 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39
- }
-};
-
-const uint8_t sha512_test_digests[][64] = {
- {
- /* for test_msg0 */
- 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA,
- 0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31,
- 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2,
- 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A,
- 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8,
- 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD,
- 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E,
- 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* for test_msg2 */
- 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA,
- 0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F,
- 0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1,
- 0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18,
- 0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4,
- 0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A,
- 0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54,
- 0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09
- }
-};
-
-const uint8_t sha512_224_test_digests[][28] = {
- {
- /* for test_msg0 */
- 0x46, 0x34, 0x27, 0x0F, 0x70, 0x7B, 0x6A, 0x54,
- 0xDA, 0xAE, 0x75, 0x30, 0x46, 0x08, 0x42, 0xE2,
- 0x0E, 0x37, 0xED, 0x26, 0x5C, 0xEE, 0xE9, 0xA4,
- 0x3E, 0x89, 0x24, 0xAA
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* for test_msg2 */
- 0x23, 0xFE, 0xC5, 0xBB, 0x94, 0xD6, 0x0B, 0x23,
- 0x30, 0x81, 0x92, 0x64, 0x0B, 0x0C, 0x45, 0x33,
- 0x35, 0xD6, 0x64, 0x73, 0x4F, 0xE4, 0x0E, 0x72,
- 0x68, 0x67, 0x4A, 0xF9
- }
-};
-
-const uint8_t sha512_256_test_digests[][32] = {
- {
- /* for test_msg0 */
- 0x53, 0x04, 0x8E, 0x26, 0x81, 0x94, 0x1E, 0xF9,
- 0x9B, 0x2E, 0x29, 0xB7, 0x6B, 0x4C, 0x7D, 0xAB,
- 0xE4, 0xC2, 0xD0, 0xC6, 0x34, 0xFC, 0x6D, 0x46,
- 0xE0, 0xE2, 0xF1, 0x31, 0x07, 0xE7, 0xAF, 0x23
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* for test_msg2 */
- 0x39, 0x28, 0xE1, 0x84, 0xFB, 0x86, 0x90, 0xF8,
- 0x40, 0xDA, 0x39, 0x88, 0x12, 0x1D, 0x31, 0xBE,
- 0x65, 0xCB, 0x9D, 0x3E, 0xF8, 0x3E, 0xE6, 0x14,
- 0x6F, 0xEA, 0xC8, 0x61, 0xE1, 0x9B, 0x56, 0x3A
- }
-};
-
-int
-main(int argc, char *argv[])
-{
- boolean_t failed = B_FALSE;
- uint64_t cpu_mhz = 0;
-
- if (argc == 2)
- cpu_mhz = atoi(argv[1]);
-
-#define SHA2_ALGO_TEST(_m, mode, diglen, testdigest) \
- do { \
- SHA2_CTX ctx; \
- uint8_t digest[diglen / 8]; \
- SHA2Init(SHA ## mode ## _MECH_INFO_TYPE, &ctx); \
- SHA2Update(&ctx, _m, strlen(_m)); \
- SHA2Final(digest, &ctx); \
- (void) printf("SHA%-9sMessage: " #_m \
- "\tResult: ", #mode); \
- if (memcmp(digest, testdigest, diglen / 8) == 0) { \
- (void) printf("OK\n"); \
- } else { \
- (void) printf("FAILED!\n"); \
- failed = B_TRUE; \
- } \
- } while (0)
-
-#define SHA2_PERF_TEST(mode, diglen) \
- do { \
- SHA2_CTX ctx; \
- uint8_t digest[diglen / 8]; \
- uint8_t block[131072]; \
- uint64_t delta; \
- double cpb = 0; \
- int i; \
- struct timeval start, end; \
- memset(block, 0, sizeof (block)); \
- (void) gettimeofday(&start, NULL); \
- SHA2Init(SHA ## mode ## _MECH_INFO_TYPE, &ctx); \
- for (i = 0; i < 8192; i++) \
- SHA2Update(&ctx, block, sizeof (block)); \
- SHA2Final(digest, &ctx); \
- (void) gettimeofday(&end, NULL); \
- delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
- (start.tv_sec * 1000000llu + start.tv_usec); \
- if (cpu_mhz != 0) { \
- cpb = (cpu_mhz * 1e6 * ((double)delta / \
- 1000000)) / (8192 * 128 * 1024); \
- } \
- (void) printf("SHA%-9s%llu us (%.02f CPB)\n", #mode, \
- (u_longlong_t)delta, cpb); \
- } while (0)
-
- (void) printf("Running algorithm correctness tests:\n");
- SHA2_ALGO_TEST(test_msg0, 256, 256, sha256_test_digests[0]);
- SHA2_ALGO_TEST(test_msg1, 256, 256, sha256_test_digests[1]);
- SHA2_ALGO_TEST(test_msg0, 384, 384, sha384_test_digests[0]);
- SHA2_ALGO_TEST(test_msg2, 384, 384, sha384_test_digests[2]);
- SHA2_ALGO_TEST(test_msg0, 512, 512, sha512_test_digests[0]);
- SHA2_ALGO_TEST(test_msg2, 512, 512, sha512_test_digests[2]);
- SHA2_ALGO_TEST(test_msg0, 512_224, 224, sha512_224_test_digests[0]);
- SHA2_ALGO_TEST(test_msg2, 512_224, 224, sha512_224_test_digests[2]);
- SHA2_ALGO_TEST(test_msg0, 512_256, 256, sha512_256_test_digests[0]);
- SHA2_ALGO_TEST(test_msg2, 512_256, 256, sha512_256_test_digests[2]);
-
- if (failed)
- return (1);
-
- (void) printf("Running performance tests (hashing 1024 MiB of "
- "data):\n");
- SHA2_PERF_TEST(256, 256);
- SHA2_PERF_TEST(512, 512);
-
- return (0);
-}
+++ /dev/null
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://opensource.org/licenses/CDDL-1.0.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2013 Saso Kiselkov. All rights reserved.
- */
-
-/*
- * This is just to keep the compiler happy about sys/time.h not declaring
- * gettimeofday due to -D_KERNEL (we can do this since we're actually
- * running in userspace, but we need -D_KERNEL for the remaining Skein code).
- */
-#ifdef _KERNEL
-#undef _KERNEL
-#endif
-
-#include <sys/skein.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <sys/stdtypes.h>
-
-/*
- * Skein test suite using values from the Skein V1.3 specification found at:
- * http://www.skein-hash.info/sites/default/files/skein1.3.pdf
- */
-
-/*
- * Test messages from the Skein spec, Appendix C.
- */
-const uint8_t test_msg0[] = {
- 0xFF
-};
-
-const uint8_t test_msg1[] = {
- 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
- 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
- 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
- 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0
-};
-
-const uint8_t test_msg2[] = {
- 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
- 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
- 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
- 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
- 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
- 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
- 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
- 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0
-};
-
-const uint8_t test_msg3[] = {
- 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
- 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
- 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
- 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
- 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
- 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
- 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
- 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0,
- 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8,
- 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0,
- 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8,
- 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0,
- 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98,
- 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
- 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88,
- 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80
-};
-
-const uint8_t test_msg4[] = {
- 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
- 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
- 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
- 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
- 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
- 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
- 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
- 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0,
- 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8,
- 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0,
- 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8,
- 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0,
- 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98,
- 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
- 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88,
- 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80,
- 0x7F, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78,
- 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70,
- 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68,
- 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x60,
- 0x5F, 0x5E, 0x5D, 0x5C, 0x5B, 0x5A, 0x59, 0x58,
- 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51, 0x50,
- 0x4F, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, 0x49, 0x48,
- 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x40,
- 0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38,
- 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30,
- 0x2F, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x28,
- 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20,
- 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
- 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
- 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
- 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00
-};
-
-/*
- * Test digests from the Skein spec, Appendix C.
- */
-const uint8_t skein_256_test_digests[][32] = {
- {
- /* for test_msg0 */
- 0x0B, 0x98, 0xDC, 0xD1, 0x98, 0xEA, 0x0E, 0x50,
- 0xA7, 0xA2, 0x44, 0xC4, 0x44, 0xE2, 0x5C, 0x23,
- 0xDA, 0x30, 0xC1, 0x0F, 0xC9, 0xA1, 0xF2, 0x70,
- 0xA6, 0x63, 0x7F, 0x1F, 0x34, 0xE6, 0x7E, 0xD2
- },
- {
- /* for test_msg1 */
- 0x8D, 0x0F, 0xA4, 0xEF, 0x77, 0x7F, 0xD7, 0x59,
- 0xDF, 0xD4, 0x04, 0x4E, 0x6F, 0x6A, 0x5A, 0xC3,
- 0xC7, 0x74, 0xAE, 0xC9, 0x43, 0xDC, 0xFC, 0x07,
- 0x92, 0x7B, 0x72, 0x3B, 0x5D, 0xBF, 0x40, 0x8B
- },
- {
- /* for test_msg2 */
- 0xDF, 0x28, 0xE9, 0x16, 0x63, 0x0D, 0x0B, 0x44,
- 0xC4, 0xA8, 0x49, 0xDC, 0x9A, 0x02, 0xF0, 0x7A,
- 0x07, 0xCB, 0x30, 0xF7, 0x32, 0x31, 0x82, 0x56,
- 0xB1, 0x5D, 0x86, 0x5A, 0xC4, 0xAE, 0x16, 0x2F
- }
- /* no test digests for test_msg3 and test_msg4 */
-};
-
-const uint8_t skein_512_test_digests[][64] = {
- {
- /* for test_msg0 */
- 0x71, 0xB7, 0xBC, 0xE6, 0xFE, 0x64, 0x52, 0x22,
- 0x7B, 0x9C, 0xED, 0x60, 0x14, 0x24, 0x9E, 0x5B,
- 0xF9, 0xA9, 0x75, 0x4C, 0x3A, 0xD6, 0x18, 0xCC,
- 0xC4, 0xE0, 0xAA, 0xE1, 0x6B, 0x31, 0x6C, 0xC8,
- 0xCA, 0x69, 0x8D, 0x86, 0x43, 0x07, 0xED, 0x3E,
- 0x80, 0xB6, 0xEF, 0x15, 0x70, 0x81, 0x2A, 0xC5,
- 0x27, 0x2D, 0xC4, 0x09, 0xB5, 0xA0, 0x12, 0xDF,
- 0x2A, 0x57, 0x91, 0x02, 0xF3, 0x40, 0x61, 0x7A
- },
- {
- /* no test vector for test_msg1 */
- 0,
- },
- {
- /* for test_msg2 */
- 0x45, 0x86, 0x3B, 0xA3, 0xBE, 0x0C, 0x4D, 0xFC,
- 0x27, 0xE7, 0x5D, 0x35, 0x84, 0x96, 0xF4, 0xAC,
- 0x9A, 0x73, 0x6A, 0x50, 0x5D, 0x93, 0x13, 0xB4,
- 0x2B, 0x2F, 0x5E, 0xAD, 0xA7, 0x9F, 0xC1, 0x7F,
- 0x63, 0x86, 0x1E, 0x94, 0x7A, 0xFB, 0x1D, 0x05,
- 0x6A, 0xA1, 0x99, 0x57, 0x5A, 0xD3, 0xF8, 0xC9,
- 0xA3, 0xCC, 0x17, 0x80, 0xB5, 0xE5, 0xFA, 0x4C,
- 0xAE, 0x05, 0x0E, 0x98, 0x98, 0x76, 0x62, 0x5B
- },
- {
- /* for test_msg3 */
- 0x91, 0xCC, 0xA5, 0x10, 0xC2, 0x63, 0xC4, 0xDD,
- 0xD0, 0x10, 0x53, 0x0A, 0x33, 0x07, 0x33, 0x09,
- 0x62, 0x86, 0x31, 0xF3, 0x08, 0x74, 0x7E, 0x1B,
- 0xCB, 0xAA, 0x90, 0xE4, 0x51, 0xCA, 0xB9, 0x2E,
- 0x51, 0x88, 0x08, 0x7A, 0xF4, 0x18, 0x87, 0x73,
- 0xA3, 0x32, 0x30, 0x3E, 0x66, 0x67, 0xA7, 0xA2,
- 0x10, 0x85, 0x6F, 0x74, 0x21, 0x39, 0x00, 0x00,
- 0x71, 0xF4, 0x8E, 0x8B, 0xA2, 0xA5, 0xAD, 0xB7
- }
- /* no test digests for test_msg4 */
-};
-
-const uint8_t skein_1024_test_digests[][128] = {
- {
- /* for test_msg0 */
- 0xE6, 0x2C, 0x05, 0x80, 0x2E, 0xA0, 0x15, 0x24,
- 0x07, 0xCD, 0xD8, 0x78, 0x7F, 0xDA, 0x9E, 0x35,
- 0x70, 0x3D, 0xE8, 0x62, 0xA4, 0xFB, 0xC1, 0x19,
- 0xCF, 0xF8, 0x59, 0x0A, 0xFE, 0x79, 0x25, 0x0B,
- 0xCC, 0xC8, 0xB3, 0xFA, 0xF1, 0xBD, 0x24, 0x22,
- 0xAB, 0x5C, 0x0D, 0x26, 0x3F, 0xB2, 0xF8, 0xAF,
- 0xB3, 0xF7, 0x96, 0xF0, 0x48, 0x00, 0x03, 0x81,
- 0x53, 0x1B, 0x6F, 0x00, 0xD8, 0x51, 0x61, 0xBC,
- 0x0F, 0xFF, 0x4B, 0xEF, 0x24, 0x86, 0xB1, 0xEB,
- 0xCD, 0x37, 0x73, 0xFA, 0xBF, 0x50, 0xAD, 0x4A,
- 0xD5, 0x63, 0x9A, 0xF9, 0x04, 0x0E, 0x3F, 0x29,
- 0xC6, 0xC9, 0x31, 0x30, 0x1B, 0xF7, 0x98, 0x32,
- 0xE9, 0xDA, 0x09, 0x85, 0x7E, 0x83, 0x1E, 0x82,
- 0xEF, 0x8B, 0x46, 0x91, 0xC2, 0x35, 0x65, 0x65,
- 0x15, 0xD4, 0x37, 0xD2, 0xBD, 0xA3, 0x3B, 0xCE,
- 0xC0, 0x01, 0xC6, 0x7F, 0xFD, 0xE1, 0x5B, 0xA8
- },
- {
- /* no test vector for test_msg1 */
- 0
- },
- {
- /* no test vector for test_msg2 */
- 0
- },
- {
- /* for test_msg3 */
- 0x1F, 0x3E, 0x02, 0xC4, 0x6F, 0xB8, 0x0A, 0x3F,
- 0xCD, 0x2D, 0xFB, 0xBC, 0x7C, 0x17, 0x38, 0x00,
- 0xB4, 0x0C, 0x60, 0xC2, 0x35, 0x4A, 0xF5, 0x51,
- 0x18, 0x9E, 0xBF, 0x43, 0x3C, 0x3D, 0x85, 0xF9,
- 0xFF, 0x18, 0x03, 0xE6, 0xD9, 0x20, 0x49, 0x31,
- 0x79, 0xED, 0x7A, 0xE7, 0xFC, 0xE6, 0x9C, 0x35,
- 0x81, 0xA5, 0xA2, 0xF8, 0x2D, 0x3E, 0x0C, 0x7A,
- 0x29, 0x55, 0x74, 0xD0, 0xCD, 0x7D, 0x21, 0x7C,
- 0x48, 0x4D, 0x2F, 0x63, 0x13, 0xD5, 0x9A, 0x77,
- 0x18, 0xEA, 0xD0, 0x7D, 0x07, 0x29, 0xC2, 0x48,
- 0x51, 0xD7, 0xE7, 0xD2, 0x49, 0x1B, 0x90, 0x2D,
- 0x48, 0x91, 0x94, 0xE6, 0xB7, 0xD3, 0x69, 0xDB,
- 0x0A, 0xB7, 0xAA, 0x10, 0x6F, 0x0E, 0xE0, 0xA3,
- 0x9A, 0x42, 0xEF, 0xC5, 0x4F, 0x18, 0xD9, 0x37,
- 0x76, 0x08, 0x09, 0x85, 0xF9, 0x07, 0x57, 0x4F,
- 0x99, 0x5E, 0xC6, 0xA3, 0x71, 0x53, 0xA5, 0x78
- },
- {
- /* for test_msg4 */
- 0x84, 0x2A, 0x53, 0xC9, 0x9C, 0x12, 0xB0, 0xCF,
- 0x80, 0xCF, 0x69, 0x49, 0x1B, 0xE5, 0xE2, 0xF7,
- 0x51, 0x5D, 0xE8, 0x73, 0x3B, 0x6E, 0xA9, 0x42,
- 0x2D, 0xFD, 0x67, 0x66, 0x65, 0xB5, 0xFA, 0x42,
- 0xFF, 0xB3, 0xA9, 0xC4, 0x8C, 0x21, 0x77, 0x77,
- 0x95, 0x08, 0x48, 0xCE, 0xCD, 0xB4, 0x8F, 0x64,
- 0x0F, 0x81, 0xFB, 0x92, 0xBE, 0xF6, 0xF8, 0x8F,
- 0x7A, 0x85, 0xC1, 0xF7, 0xCD, 0x14, 0x46, 0xC9,
- 0x16, 0x1C, 0x0A, 0xFE, 0x8F, 0x25, 0xAE, 0x44,
- 0x4F, 0x40, 0xD3, 0x68, 0x00, 0x81, 0xC3, 0x5A,
- 0xA4, 0x3F, 0x64, 0x0F, 0xD5, 0xFA, 0x3C, 0x3C,
- 0x03, 0x0B, 0xCC, 0x06, 0xAB, 0xAC, 0x01, 0xD0,
- 0x98, 0xBC, 0xC9, 0x84, 0xEB, 0xD8, 0x32, 0x27,
- 0x12, 0x92, 0x1E, 0x00, 0xB1, 0xBA, 0x07, 0xD6,
- 0xD0, 0x1F, 0x26, 0x90, 0x70, 0x50, 0x25, 0x5E,
- 0xF2, 0xC8, 0xE2, 0x4F, 0x71, 0x6C, 0x52, 0xA5
- }
-};
-
-int
-main(int argc, char *argv[])
-{
- boolean_t failed = B_FALSE;
- uint64_t cpu_mhz = 0;
-
- if (argc == 2)
- cpu_mhz = atoi(argv[1]);
-
-#define SKEIN_ALGO_TEST(_m, mode, diglen, testdigest) \
- do { \
- Skein ## mode ## _Ctxt_t ctx; \
- uint8_t digest[diglen / 8]; \
- (void) Skein ## mode ## _Init(&ctx, diglen); \
- (void) Skein ## mode ## _Update(&ctx, _m, sizeof (_m)); \
- (void) Skein ## mode ## _Final(&ctx, digest); \
- (void) printf("Skein" #mode "/" #diglen \
- "\tMessage: " #_m "\tResult: "); \
- if (memcmp(digest, testdigest, diglen / 8) == 0) { \
- (void) printf("OK\n"); \
- } else { \
- (void) printf("FAILED!\n"); \
- failed = B_TRUE; \
- } \
- } while (0)
-
-#define SKEIN_PERF_TEST(mode, diglen) \
- do { \
- Skein ## mode ## _Ctxt_t ctx; \
- uint8_t digest[diglen / 8]; \
- uint8_t block[131072]; \
- uint64_t delta; \
- double cpb = 0; \
- int i; \
- struct timeval start, end; \
- memset(block, 0, sizeof (block)); \
- (void) gettimeofday(&start, NULL); \
- (void) Skein ## mode ## _Init(&ctx, diglen); \
- for (i = 0; i < 8192; i++) { \
- (void) Skein ## mode ## _Update(&ctx, block, \
- sizeof (block)); \
- } \
- (void) Skein ## mode ## _Final(&ctx, digest); \
- (void) gettimeofday(&end, NULL); \
- delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
- (start.tv_sec * 1000000llu + start.tv_usec); \
- if (cpu_mhz != 0) { \
- cpb = (cpu_mhz * 1e6 * ((double)delta / \
- 1000000)) / (8192 * 128 * 1024); \
- } \
- (void) printf("Skein" #mode "/" #diglen "\t%llu us " \
- "(%.02f CPB)\n", (u_longlong_t)delta, cpb); \
- } while (0)
-
- (void) printf("Running algorithm correctness tests:\n");
- SKEIN_ALGO_TEST(test_msg0, _256, 256, skein_256_test_digests[0]);
- SKEIN_ALGO_TEST(test_msg1, _256, 256, skein_256_test_digests[1]);
- SKEIN_ALGO_TEST(test_msg2, _256, 256, skein_256_test_digests[2]);
- SKEIN_ALGO_TEST(test_msg0, _512, 512, skein_512_test_digests[0]);
- SKEIN_ALGO_TEST(test_msg2, _512, 512, skein_512_test_digests[2]);
- SKEIN_ALGO_TEST(test_msg3, _512, 512, skein_512_test_digests[3]);
- SKEIN_ALGO_TEST(test_msg0, 1024, 1024, skein_1024_test_digests[0]);
- SKEIN_ALGO_TEST(test_msg3, 1024, 1024, skein_1024_test_digests[3]);
- SKEIN_ALGO_TEST(test_msg4, 1024, 1024, skein_1024_test_digests[4]);
- if (failed)
- return (1);
-
- (void) printf("Running performance tests (hashing 1024 MiB of "
- "data):\n");
- SKEIN_PERF_TEST(_256, 256);
- SKEIN_PERF_TEST(_512, 512);
- SKEIN_PERF_TEST(1024, 1024);
-
- return (0);
-}
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_diff
dist_pkgdata_SCRIPTS = \
zfs_diff_mangle.ksh \
zfs_diff_timestamp.ksh \
zfs_diff_types.ksh
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_diff
-
-pkgexec_PROGRAMS = socket
-socket_SOURCES = socket.c
+++ /dev/null
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source. A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
- */
-
-#include <fcntl.h>
-#include <sys/un.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int
-main(int argc, char *argv[])
-{
- struct sockaddr_un sock;
- int fd;
- char *path;
- size_t size;
- if (argc != 2) {
- fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]);
- exit(1);
- }
- path = argv[1];
- size = sizeof (sock.sun_path);
- strncpy(sock.sun_path, (char *)path, size - 1);
- sock.sun_path[size - 1] = '\0';
-
- sock.sun_family = AF_UNIX;
- if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
- perror("socket");
- return (1);
- }
- if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) {
- perror("bind");
- return (1);
- }
- if (close(fd)) {
- perror("close");
- return (1);
- }
- return (0);
-}
# 2. = (Socket)
log_must zfs snapshot "$TESTSNAP1"
-log_must $STF_SUITE/tests/functional/cli_root/zfs_diff/socket "$MNTPOINT/sock"
+log_must zfs_diff-socket "$MNTPOINT/sock"
log_must zfs snapshot "$TESTSNAP2"
verify_object_class "$MNTPOINT/sock" "="
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_events
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_events
dist_pkgdata_SCRIPTS = \
setup.ksh \
dist_pkgdata_DATA = \
zpool_events.cfg \
zpool_events.kshlib
-
-ereports_LDADD = \
- $(abs_top_builddir)/lib/libnvpair/libnvpair.la \
- $(abs_top_builddir)/lib/libzfs/libzfs.la
-
-pkgexec_PROGRAMS = ereports
-ereports_SOURCES = ereports.c
+++ /dev/null
-/*
- * CDDL HEADER START
- *
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source. A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 2020 by Delphix. All rights reserved.
- */
-
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <libzfs.h>
-#include <sys/zfs_ioctl.h>
-#include <sys/nvpair.h>
-#include <sys/fm/protocol.h>
-#include <sys/fm/fs/zfs.h>
-
-/*
- * Command to output io and checksum ereport values, one per line.
- * Used by zpool_events_duplicates.ksh to check for duplicate events.
- *
- * example output line:
- *
- * checksum "error_pool" 0x856dd01ce52e336 0x000034 0x000400 0x000a402c00
- * 0x000004 0x000000 0x000000 0x000000 0x000001
- */
-
-/*
- * Our ereport duplicate criteria
- *
- * When the class and all of these values match, then an ereport is
- * considered to be a duplicate.
- */
-static const char *criteria_name[] = {
- FM_EREPORT_PAYLOAD_ZFS_POOL,
- FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_PRIORITY,
-
- /* logical zio criteriai (optional) */
- FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
- FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
-};
-
-#define CRITERIA_NAMES_COUNT ARRAY_SIZE(criteria_name)
-
-static void
-print_ereport_line(nvlist_t *nvl)
-{
- char *class;
- int last = CRITERIA_NAMES_COUNT - 1;
-
- /*
- * For the test case context, we only want to see 'io' and
- * 'checksum' subclass. We skip 'data' to minimize the output.
- */
- if (nvlist_lookup_string(nvl, FM_CLASS, &class) != 0 ||
- strstr(class, "ereport.fs.zfs.") == NULL ||
- strcmp(class, "ereport.fs.zfs.data") == 0) {
- return;
- }
-
- (void) printf("%s\t", class + strlen("ereport.fs.zfs."));
-
- for (int i = 0; i < CRITERIA_NAMES_COUNT; i++) {
- nvpair_t *nvp;
- uint32_t i32 = 0;
- uint64_t i64 = 0;
- char *str = NULL;
-
- if (nvlist_lookup_nvpair(nvl, criteria_name[i], &nvp) != 0) {
- /* print a proxy for optional criteria */
- (void) printf("--------");
- (void) printf("%c", i == last ? '\n' : '\t');
- continue;
- }
-
- switch (nvpair_type(nvp)) {
- case DATA_TYPE_STRING:
- (void) nvpair_value_string(nvp, &str);
- (void) printf("\"%s\"", str ? str : "<NULL>");
- break;
-
- case DATA_TYPE_INT32:
- (void) nvpair_value_int32(nvp, (void *)&i32);
- (void) printf("0x%06x", i32);
- break;
-
- case DATA_TYPE_UINT32:
- (void) nvpair_value_uint32(nvp, &i32);
- (void) printf("0x%06x", i32);
- break;
-
- case DATA_TYPE_INT64:
- (void) nvpair_value_int64(nvp, (void *)&i64);
- (void) printf("0x%06llx", (u_longlong_t)i64);
- break;
-
- case DATA_TYPE_UINT64:
- (void) nvpair_value_uint64(nvp, &i64);
- if (strcmp(FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
- criteria_name[i]) == 0)
- (void) printf("0x%010llx", (u_longlong_t)i64);
- else
- (void) printf("0x%06llx", (u_longlong_t)i64);
- break;
- default:
- (void) printf("<unknown>");
- break;
- }
- (void) printf("%c", i == last ? '\n' : '\t');
- }
-}
-
-static void
-ereports_dump(libzfs_handle_t *zhdl, int zevent_fd)
-{
- nvlist_t *nvl;
- int ret, dropped;
-
- while (1) {
- ret = zpool_events_next(zhdl, &nvl, &dropped, ZEVENT_NONBLOCK,
- zevent_fd);
- if (ret || nvl == NULL)
- break;
- if (dropped > 0)
- (void) fprintf(stdout, "dropped %d events\n", dropped);
- print_ereport_line(nvl);
- (void) fflush(stdout);
- nvlist_free(nvl);
- }
-}
-
-int
-main(void)
-{
- libzfs_handle_t *hdl;
- int fd;
-
- hdl = libzfs_init();
- if (hdl == NULL) {
- (void) fprintf(stderr, "libzfs_init: %s\n", strerror(errno));
- exit(2);
- }
- fd = open(ZFS_DEV, O_RDWR);
- if (fd < 0) {
- (void) fprintf(stderr, "open: %s\n", strerror(errno));
- libzfs_fini(hdl);
- exit(2);
- }
-
- ereports_dump(hdl, fd);
-
- (void) close(fd);
- libzfs_fini(hdl);
-
- return (0);
-}
RETAIN_MAX=$(get_tunable ZEVENT_RETAIN_MAX)
OLD_CHECKSUMS=$(get_tunable CHECKSUM_EVENTS_PER_SECOND)
-EREPORTS="$STF_SUITE/tests/functional/cli_root/zpool_events/ereports"
-
function cleanup
{
log_must set_tunable64 CHECKSUM_EVENTS_PER_SECOND $OLD_CHECKSUMS
log_must dd conv=notrunc if=$SUPPLY of=$VDEV1 bs=1M seek=4 count=$DAMAGEBLKS
log_must zpool scrub $POOL
log_must zpool wait -t scrub $POOL
- log_note "pass $1 observed $($EREPORTS | grep -c checksum) checksum ereports"
+ log_note "pass $1 observed $(ereports | grep -c checksum) checksum ereports"
repaired=$(zpool status $POOL | awk '/scan: scrub repaired/ {print $4}')
if [ "$repaired" == "0B" ]; then
OLD_LEN_MAX=$(get_tunable ZEVENT_LEN_MAX)
RETAIN_MAX=$(get_tunable ZEVENT_RETAIN_MAX)
-EREPORTS="$STF_SUITE/tests/functional/cli_root/zpool_events/ereports"
-
duplicates=false
function cleanup
log_must zinject -c all
- ereports="$($EREPORTS | sort)"
+ ereports="$(ereports | sort)"
actual=$(echo "$ereports" | wc -l)
unique=$(echo "$ereports" | uniq | wc -l)
log_note "$actual total $ERR $RW ereports where $unique were unique"
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cp_files
dist_pkgdata_SCRIPTS = \
cp_files_001_pos.ksh \
cleanup.ksh \
setup.ksh
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cp_files
-
-pkgexec_PROGRAMS = cp_files
-cp_files_SOURCES= cp_files.c
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
-
-int
-main(int argc, char *argv[])
-{
- int tfd;
- DIR *sdir;
- struct dirent *dirent;
-
- if (argc != 3) {
- fprintf(stderr, "Usage: %s SRC DST\n", argv[0]);
- exit(1);
- }
-
- sdir = opendir(argv[1]);
- if (sdir == NULL) {
- fprintf(stderr, "Failed to open %s: %s\n",
- argv[1], strerror(errno));
- exit(2);
- }
-
- tfd = open(argv[2], O_DIRECTORY);
- if (tfd < 0) {
- fprintf(stderr, "Failed to open %s: %s\n",
- argv[2], strerror(errno));
- closedir(sdir);
- exit(3);
- }
-
- while ((dirent = readdir(sdir)) != NULL) {
- if (dirent->d_name[0] == '.' &&
- (dirent->d_name[1] == '.' || dirent->d_name[1] == '\0'))
- continue;
-
- int fd = openat(tfd, dirent->d_name, O_CREAT|O_WRONLY, 0666);
- if (fd < 0) {
- fprintf(stderr, "Failed to create %s/%s: %s\n",
- argv[2], dirent->d_name, strerror(errno));
- closedir(sdir);
- close(tfd);
- exit(4);
- }
- close(fd);
- }
-
- closedir(sdir);
- close(tfd);
-
- return (0);
-}
NR_FILES=60000
BATCH=1000
-log_must mkdir $TESTDIR/src
-log_must mkdir $TESTDIR/dst
+log_must mkdir $TESTDIR/src $TESTDIR/dst
WD=$PWD
cd $TESTDIR/src
log_must test $NR_FILES -eq $(ls -U $TESTDIR/src | wc -l)
# copy files from src to dst, use cp_files to make sure we copy in readdir order
-log_must $STF_SUITE/tests/functional/cp_files/cp_files $TESTDIR/src $TESTDIR/dst
+log_must cp_files $TESTDIR/src $TESTDIR/dst
log_must test $NR_FILES -eq $(ls -U $TESTDIR/dst | wc -l)
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime
dist_pkgdata_SCRIPTS = \
ctime_001_pos.ksh \
cleanup.ksh \
setup.ksh
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime
-
-pkgexec_PROGRAMS = ctime
-ctime_SOURCES = ctime.c
+++ /dev/null
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-/*
- * Copyright (c) 2013 by Delphix. All rights reserved.
- */
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifndef __FreeBSD__
-#include <sys/xattr.h>
-#endif
-#include <utime.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <libgen.h>
-#include <string.h>
-
-#define ST_ATIME 0
-#define ST_CTIME 1
-#define ST_MTIME 2
-
-#define ALL_MODE (mode_t)(S_IRWXU|S_IRWXG|S_IRWXO)
-
-typedef struct timetest {
- int type;
- char *name;
- int (*func)(const char *pfile);
-} timetest_t;
-
-static char tfile[BUFSIZ] = { 0 };
-
-/*
- * DESCRIPTION:
- * Verify time will be changed correctly after each operation.
- *
- * STRATEGY:
- * 1. Define time test array.
- * 2. Loop through each item in this array.
- * 3. Verify the time is changed after each operation.
- *
- */
-
-static int
-get_file_time(const char *pfile, int what, time_t *ptr)
-{
- struct stat stat_buf;
-
- if (pfile == NULL || ptr == NULL) {
- return (-1);
- }
-
- if (stat(pfile, &stat_buf) == -1) {
- return (-1);
- }
-
- switch (what) {
- case ST_ATIME:
- *ptr = stat_buf.st_atime;
- return (0);
- case ST_CTIME:
- *ptr = stat_buf.st_ctime;
- return (0);
- case ST_MTIME:
- *ptr = stat_buf.st_mtime;
- return (0);
- default:
- return (-1);
- }
-}
-
-static ssize_t
-get_dirnamelen(const char *path)
-{
- const char *end = strrchr(path, '/');
- return (end ? end - path : -1);
-}
-
-static int
-do_read(const char *pfile)
-{
- int fd, ret = 0;
- char buf[BUFSIZ] = { 0 };
-
- if (pfile == NULL) {
- return (-1);
- }
-
- if ((fd = open(pfile, O_RDONLY, ALL_MODE)) == -1) {
- return (-1);
- }
- if (read(fd, buf, sizeof (buf)) == -1) {
- (void) fprintf(stderr, "read(%d, buf, %zd) failed with errno "
- "%d\n", fd, sizeof (buf), errno);
- (void) close(fd);
- return (1);
- }
- (void) close(fd);
-
- return (ret);
-}
-
-static int
-do_write(const char *pfile)
-{
- int fd, ret = 0;
- char buf[BUFSIZ] = "call function do_write()";
-
- if (pfile == NULL) {
- return (-1);
- }
-
- if ((fd = open(pfile, O_WRONLY, ALL_MODE)) == -1) {
- return (-1);
- }
- if (write(fd, buf, strlen(buf)) == -1) {
- (void) fprintf(stderr, "write(%d, buf, %d) failed with errno "
- "%d\n", fd, (int)strlen(buf), errno);
- (void) close(fd);
- return (1);
- }
- (void) close(fd);
-
- return (ret);
-}
-
-static int
-do_link(const char *pfile)
-{
- int ret = 0;
- char link_file[BUFSIZ + 16] = { 0 };
-
- if (pfile == NULL) {
- return (-1);
- }
-
- /*
- * Figure out source file directory name, and create
- * the link file in the same directory.
- */
- (void) snprintf(link_file, sizeof (link_file),
- "%.*s/%s", (int)get_dirnamelen(pfile), pfile, "link_file");
-
- if (link(pfile, link_file) == -1) {
- (void) fprintf(stderr, "link(%s, %s) failed with errno %d\n",
- pfile, link_file, errno);
- return (1);
- }
-
- (void) unlink(link_file);
-
- return (ret);
-}
-
-static int
-do_creat(const char *pfile)
-{
- int fd, ret = 0;
-
- if (pfile == NULL) {
- return (-1);
- }
-
- if ((fd = creat(pfile, ALL_MODE)) == -1) {
- (void) fprintf(stderr, "creat(%s, ALL_MODE) failed with errno "
- "%d\n", pfile, errno);
- return (1);
- }
- (void) close(fd);
-
- return (ret);
-}
-
-static int
-do_utime(const char *pfile)
-{
- int ret = 0;
-
- if (pfile == NULL) {
- return (-1);
- }
-
- /*
- * Times of the file are set to the current time
- */
- if (utime(pfile, NULL) == -1) {
- (void) fprintf(stderr, "utime(%s, NULL) failed with errno "
- "%d\n", pfile, errno);
- return (1);
- }
-
- return (ret);
-}
-
-static int
-do_chmod(const char *pfile)
-{
- int ret = 0;
-
- if (pfile == NULL) {
- return (-1);
- }
-
- if (chmod(pfile, ALL_MODE) == -1) {
- (void) fprintf(stderr, "chmod(%s, ALL_MODE) failed with "
- "errno %d\n", pfile, errno);
- return (1);
- }
-
- return (ret);
-}
-
-static int
-do_chown(const char *pfile)
-{
- int ret = 0;
-
- if (pfile == NULL) {
- return (-1);
- }
-
- if (chown(pfile, getuid(), getgid()) == -1) {
- (void) fprintf(stderr, "chown(%s, %d, %d) failed with errno "
- "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
- return (1);
- }
-
- return (ret);
-}
-
-#ifndef __FreeBSD__
-static int
-do_xattr(const char *pfile)
-{
- int ret = 0;
- char *value = "user.value";
-
- if (pfile == NULL) {
- return (-1);
- }
-
- if (setxattr(pfile, "user.x", value, strlen(value), 0) == -1) {
- (void) fprintf(stderr, "setxattr(%s, %d, %d) failed with errno "
- "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
- return (1);
- }
- return (ret);
-}
-#endif
-
-static void
-cleanup(void)
-{
- if ((strlen(tfile) != 0) && (access(tfile, F_OK) == 0)) {
- (void) unlink(tfile);
- }
-}
-
-static timetest_t timetest_table[] = {
- { ST_ATIME, "st_atime", do_read },
- { ST_ATIME, "st_atime", do_utime },
- { ST_MTIME, "st_mtime", do_creat },
- { ST_MTIME, "st_mtime", do_write },
- { ST_MTIME, "st_mtime", do_utime },
- { ST_CTIME, "st_ctime", do_creat },
- { ST_CTIME, "st_ctime", do_write },
- { ST_CTIME, "st_ctime", do_chmod },
- { ST_CTIME, "st_ctime", do_chown },
- { ST_CTIME, "st_ctime", do_link },
- { ST_CTIME, "st_ctime", do_utime },
-#ifndef __FreeBSD__
- { ST_CTIME, "st_ctime", do_xattr },
-#endif
-};
-
-#define NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0]))
-
-int
-main(void)
-{
- int i, ret, fd;
- char *penv[] = {"TESTDIR", "TESTFILE0"};
-
- (void) atexit(cleanup);
-
- /*
- * Get the environment variable values.
- */
- for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
- if ((penv[i] = getenv(penv[i])) == NULL) {
- (void) fprintf(stderr, "getenv(penv[%d])\n", i);
- return (1);
- }
- }
- (void) snprintf(tfile, sizeof (tfile), "%s/%s", penv[0], penv[1]);
-
- /*
- * If the test file exists, remove it first.
- */
- if (access(tfile, F_OK) == 0) {
- (void) unlink(tfile);
- }
- ret = 0;
- if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
- (void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
- return (1);
- }
- (void) close(fd);
-
- for (i = 0; i < NCOMMAND; i++) {
- time_t t1, t2;
-
- /*
- * Get original time before operating.
- */
- ret = get_file_time(tfile, timetest_table[i].type, &t1);
- if (ret != 0) {
- (void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
- tfile, timetest_table[i].type, ret);
- return (1);
- }
-
- /*
- * Sleep 2 seconds, then invoke command on given file
- */
- (void) sleep(2);
- timetest_table[i].func(tfile);
-
- /*
- * Get time after operating.
- */
- ret = get_file_time(tfile, timetest_table[i].type, &t2);
- if (ret != 0) {
- (void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
- tfile, timetest_table[i].type, ret);
- return (1);
- }
-
- if (t1 == t2) {
- (void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
- timetest_table[i].name, (long)t1, (long)t2);
- return (1);
- } else {
- (void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
- timetest_table[i].name, (long)t1, (long)t2);
- }
- }
-
- return (0);
-}
for arg in ${args[*]}; do
log_note "Testing with xattr set to $arg"
log_must zfs set xattr=$arg $TESTPOOL
- log_must $STF_SUITE/tests/functional/ctime/ctime
+ log_must ctime
done
log_pass "PASS"
+++ /dev/null
-/zed_fd_spill-zedlet
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/events
dist_pkgdata_SCRIPTS = \
setup.ksh \
dist_pkgdata_DATA = \
events.cfg \
events_common.kshlib
-
-pkgexecdir = $(pkgdatadir)
-pkgexec_PROGRAMS = zed_fd_spill-zedlet
-zed_fd_spill_zedlet_SOURCES = zed_fd_spill-zedlet.c
+++ /dev/null
-/*
- * Permission to use, copy, modify, and/or distribute this software for
- * any purpose with or without fee is hereby granted.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-int main(void) {
- if (fork()) {
- int err;
- wait(&err);
- return (err);
- }
-
- char buf[64];
- sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid());
- dup2(creat(buf, 0644), STDOUT_FILENO);
-
- snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid());
- execlp("ls", "ls", buf, NULL);
- _exit(127);
-}
log_must ln -s "$logdir" /tmp/zts-zed_fd_spill-logdir
-self="$(readlink -f "$0")"
-zedlet="${self%/*}/zed_fd_spill-zedlet"
-log_must ln -s $zedlet "${ZEDLET_DIR}/all-dumpfds"
+zedlet="$(command -v zed_fd_spill-zedlet)"
+log_must ln -s "$zedlet" "${ZEDLET_DIR}/all-dumpfds"
# zed will cry foul and refuse to run it if this isn't true
-sudo chown root $zedlet
-sudo chmod 700 $zedlet
+sudo chown root "$zedlet"
+sudo chmod 700 "$zedlet"
log_must zpool events -c
log_must zed_stop
include $(top_srcdir)/config/Rules.am
-pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/hkdf
-
-dist_pkgdata_SCRIPTS = \
- setup.ksh \
- cleanup.ksh \
- run_hkdf_test.ksh
-
pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/hkdf
-pkgexec_PROGRAMS = \
- hkdf_test
-
+pkgexec_PROGRAMS = hkdf_test
hkdf_test_SOURCES = hkdf_test.c
hkdf_test_LDADD = \
$(abs_top_builddir)/lib/libzpool/libzpool.la
+++ /dev/null
-#!/bin/ksh
-
-#
-# This file and its contents are supplied under the terms of the
-# Common Development and Distribution License ("CDDL"), version 1.0.
-# You may only use this file in accordance with the terms of version
-# 1.0 of the CDDL.
-#
-# A full copy of the text of the CDDL should have accompanied this
-# source. A copy of the CDDL is also available via the Internet at
-# http://www.illumos.org/license/CDDL.
-#
-
-#
-# Copyright (c) 2017 by Datto Inc. All rights reserved.
-#
-
-. $STF_SUITE/include/libtest.shlib
-
-verify_runnable "global"
-
-log_pass
+++ /dev/null
-#!/bin/ksh
-
-#
-# This file and its contents are supplied under the terms of the
-# Common Development and Distribution License ("CDDL"), version 1.0.
-# You may only use this file in accordance with the terms of version
-# 1.0 of the CDDL.
-#
-# A full copy of the text of the CDDL should have accompanied this
-# source. A copy of the CDDL is also available via the Internet at
-# http://www.illumos.org/license/CDDL.
-#
-
-#
-# Copyright (c) 2017 by Datto Inc. All rights reserved.
-#
-
-. $STF_SUITE/include/libtest.shlib
-
-#
-# DESCRIPTION:
-# Call the hkdf_test tool to test ZFS's HKDF implementation against
-# a few test vectors.
-#
-
-log_assert "Run the tests for the HKDF algorithm."
-
-log_must $STF_SUITE/tests/functional/hkdf/hkdf_test
-
-log_pass "HKDF tests pass."
+++ /dev/null
-#!/bin/ksh
-
-#
-# This file and its contents are supplied under the terms of the
-# Common Development and Distribution License ("CDDL"), version 1.0.
-# You may only use this file in accordance with the terms of version
-# 1.0 of the CDDL.
-#
-# A full copy of the text of the CDDL should have accompanied this
-# source. A copy of the CDDL is also available via the Internet at
-# http://www.illumos.org/license/CDDL.
-#
-
-#
-# Copyright (c) 2017 by Datto Inc. All rights reserved.
-#
-
-. $STF_SUITE/include/libtest.shlib
-
-verify_runnable "global"
-
-log_pass
include $(top_srcdir)/config/Rules.am
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/libzfs
-
pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/libzfs
dist_pkgdata_SCRIPTS = \
setup.ksh \
libzfs_input.ksh
-many_fds_LDADD = \
- $(abs_top_builddir)/lib/libzfs/libzfs.la
-
pkgexec_PROGRAMS = many_fds
many_fds_SOURCES = many_fds.c
-
+many_fds_LDADD = \
+ $(abs_top_builddir)/lib/libzfs/libzfs.la
+++ /dev/null
-/suid_write_to_file
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/suid
dist_pkgdata_SCRIPTS = \
suid_write_zil_replay.ksh \
cleanup.ksh \
setup.ksh
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/suid
-
-pkgexec_PROGRAMS = suid_write_to_file
-suid_write_to_file_SOURCES = suid_write_to_file.c
+++ /dev/null
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdbool.h>
-
-int
-main(int argc, char *argv[])
-{
- const char *name, *phase;
- mode_t extra;
- struct stat st;
-
- if (argc < 3) {
- fprintf(stderr, "Invalid argc\n");
- exit(1);
- }
-
- name = argv[1];
- if (strcmp(name, "SUID") == 0) {
- extra = S_ISUID;
- } else if (strcmp(name, "SGID") == 0) {
- extra = S_ISGID;
- } else if (strcmp(name, "SUID_SGID") == 0) {
- extra = S_ISUID | S_ISGID;
- } else if (strcmp(name, "NONE") == 0) {
- extra = 0;
- } else {
- fprintf(stderr, "Invalid name %s\n", name);
- exit(1);
- }
-
- const char *testdir = getenv("TESTDIR");
- if (!testdir) {
- fprintf(stderr, "getenv(TESTDIR)\n");
- exit(1);
- }
-
- umask(0);
- if (stat(testdir, &st) == -1 && mkdir(testdir, 0777) == -1) {
- perror("mkdir");
- exit(2);
- }
-
- char fpath[1024];
- snprintf(fpath, sizeof (fpath), "%s/%s", testdir, name);
-
-
- phase = argv[2];
- if (strcmp(phase, "PRECRASH") == 0) {
-
- /* clean up last run */
- unlink(fpath);
- if (stat(fpath, &st) == 0) {
- fprintf(stderr, "%s exists\n", fpath);
- exit(3);
- }
-
- int fd;
-
- fd = creat(fpath, 0777 | extra);
- if (fd == -1) {
- perror("creat");
- exit(4);
- }
- close(fd);
-
- if (setuid(65534) == -1) {
- perror("setuid");
- exit(5);
- }
-
- fd = open(fpath, O_RDWR);
- if (fd == -1) {
- perror("open");
- exit(6);
- }
-
- const char buf[] = "test";
- if (write(fd, buf, sizeof (buf)) == -1) {
- perror("write");
- exit(7);
- }
- close(fd);
-
- } else if (strcmp(phase, "REPLAY") == 0) {
- /* created in PRECRASH run */
- } else {
- fprintf(stderr, "Invalid phase %s\n", phase);
- exit(1);
- }
-
- if (stat(fpath, &st) == -1) {
- perror("stat");
- exit(8);
- }
-
- /* Verify SUID/SGID are dropped */
- mode_t res = st.st_mode & (0777 | S_ISUID | S_ISGID);
- if (res != 0777) {
- fprintf(stderr, "stat(2) %o\n", res);
- exit(9);
- }
-
- return (0);
-}
log_onexit cleanup
log_note "Verify write(2) to regular file by non-owner"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "NONE" "PRECRASH"
+log_must suid_write_to_file "NONE" "PRECRASH"
log_pass "Verify write(2) to regular file by non-owner passed"
log_onexit cleanup
log_note "Verify write(2) to SGID file by non-owner"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SGID" "PRECRASH"
+log_must suid_write_to_file "SGID" "PRECRASH"
log_pass "Verify write(2) to SGID file by non-owner passed"
log_onexit cleanup
log_note "Verify write(2) to SUID file by non-owner"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SUID" "PRECRASH"
+log_must suid_write_to_file "SUID" "PRECRASH"
log_pass "Verify write(2) to SUID file by non-owner passed"
log_onexit cleanup
log_note "Verify write(2) to SUID/SGID file by non-owner"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SUID_SGID" "PRECRASH"
+log_must suid_write_to_file "SUID_SGID" "PRECRASH"
log_pass "Verify write(2) to SUID/SGID file by non-owner passed"
#
# 3. Unprivileged write to a setuid file
#
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "NONE" "PRECRASH"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SUID" "PRECRASH"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SGID" "PRECRASH"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SUID_SGID" "PRECRASH"
+log_must suid_write_to_file "NONE" "PRECRASH"
+log_must suid_write_to_file "SUID" "PRECRASH"
+log_must suid_write_to_file "SGID" "PRECRASH"
+log_must suid_write_to_file "SUID_SGID" "PRECRASH"
#
# 4. Unmount filesystem and export the pool
#
log_must zpool import -f -d $VDIR $TESTPOOL
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "NONE" "REPLAY"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SUID" "REPLAY"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SGID" "REPLAY"
-log_must $STF_SUITE/tests/functional/suid/suid_write_to_file "SUID_SGID" "REPLAY"
+log_must suid_write_to_file "NONE" "REPLAY"
+log_must suid_write_to_file "SUID" "REPLAY"
+log_must suid_write_to_file "SGID" "REPLAY"
+log_must suid_write_to_file "SUID_SGID" "REPLAY"
log_pass
+++ /dev/null
-/truncate_test
-include $(top_srcdir)/config/Rules.am
-
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/truncate
dist_pkgdata_SCRIPTS = \
dist_pkgdata_DATA = \
truncate.cfg
-
-pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/truncate
-
-pkgexec_PROGRAMS = truncate_test
-truncate_test_SOURCES = truncate_test.c
+++ /dev/null
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source. A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
- * Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
- */
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#define FSIZE 256*1024*1024
-
-static long fsize = FSIZE;
-static int errflag = 0;
-static char *filename = NULL;
-static int ftruncflag = 0;
-
-static void parse_options(int argc, char *argv[]);
-
-static void
-usage(char *execname)
-{
- (void) fprintf(stderr,
- "usage: %s [-s filesize] [-f] /path/to/file\n", execname);
- (void) exit(1);
-}
-
-int
-main(int argc, char *argv[])
-{
- int fd;
-
- parse_options(argc, argv);
-
- if (ftruncflag) {
- fd = open(filename, O_RDWR|O_CREAT, 0666);
- if (fd < 0) {
- perror("open");
- return (1);
- }
- if (ftruncate(fd, fsize) < 0) {
- perror("ftruncate");
- return (1);
- }
- if (close(fd)) {
- perror("close");
- return (1);
- }
- } else {
- if (truncate(filename, fsize) < 0) {
- perror("truncate");
- return (1);
- }
- }
- return (0);
-}
-
-static void
-parse_options(int argc, char *argv[])
-{
- int c;
- extern char *optarg;
- extern int optind, optopt;
-
- while ((c = getopt(argc, argv, "s:f")) != -1) {
- switch (c) {
- case 's':
- fsize = atoi(optarg);
- break;
- case 'f':
- ftruncflag++;
- break;
- case ':':
- (void) fprintf(stderr,
- "Option -%c requires an operand\n", optopt);
- errflag++;
- break;
- }
- if (errflag) {
- (void) usage(argv[0]);
- }
- }
-
- if (argc <= optind) {
- (void) fprintf(stderr, "No filename specified\n");
- usage(argv[0]);
- }
- filename = argv[optind];
-}
typeset -i timestm="$(stat -f "%m" $filename)"
typeset -i timestc="$(stat -f "%c" $filename)"
log_must sleep 1
- log_must $STF_SUITE/tests/functional/truncate/truncate_test -s $size $filename $option
+ log_must truncate_test -s $size $filename $option
verify_eq $size "$(stat_size $filename)" "size"
verify_ne $timestm "$(stat -f "%m" $filename)" "mtime"
verify_ne $timestc "$(stat -f "%c" $filename)" "ctime"
typeset -i timestm="$(stat -c %Y $filename)"
typeset -i timestc="$(stat -c %Z $filename)"
log_must sleep 1
- log_must $STF_SUITE/tests/functional/truncate/truncate_test -s $size $filename $option
+ log_must truncate_test -s $size $filename $option
verify_eq $size "$(stat_size $filename)" "size"
verify_ne $timestm "$(stat -c %Y $filename)" "mtime"
verify_ne $timestc "$(stat -c %Z $filename)" "ctime"