diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2017-11-04 21:01:08 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2017-11-04 21:01:08 +0000 |
commit | b77f4de57f4048774e8a78fac9934b58d33b6a68 (patch) | |
tree | 917e55edd4852e89c071f01f4c375efcf6f82116 /utils | |
parent | 3d464ff0b558af456cd4baa79b609a0940489487 (diff) | |
download | sg3_utils-b77f4de57f4048774e8a78fac9934b58d33b6a68.tar.gz |
move some testing utilities out of the 'examples' and 'utils' directory into the new 'testing' directory; sg_vpd: add enclosure services device characteristics vpage
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@729 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Makefile | 9 | ||||
-rw-r--r-- | utils/Makefile.freebsd | 4 | ||||
-rw-r--r-- | utils/Makefile.solaris | 4 | ||||
-rw-r--r-- | utils/README | 15 | ||||
-rw-r--r-- | utils/sg_chk_asc.c | 216 | ||||
-rw-r--r-- | utils/tst_sg_lib.c | 469 |
6 files changed, 4 insertions, 713 deletions
diff --git a/utils/Makefile b/utils/Makefile index aa11a7d1..985c2c63 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -8,7 +8,7 @@ CC = gcc LD = gcc EXECS = hxascdmp -EXTRA_EXECS = hxascdmp sg_chk_asc tst_sg_lib +EXTRA_EXECS = hxascdmp MAN_PGS = hxascdmp.1 MAN_PREF = man1 @@ -30,13 +30,6 @@ clean: hxascdmp: hxascdmp.o $(LD) -o $@ $(LDFLAGS) $^ -# building sg_chk_asc depends on a prior successful make in ../lib -sg_chk_asc: sg_chk_asc.o ../lib/sg_lib.o ../lib/sg_lib_data.o - $(LD) -o $@ $(LDFLAGS) $^ - -tst_sg_lib: tst_sg_lib.o ../lib/sg_lib.o ../lib/sg_lib_data.o - $(LD) -o $@ $(LDFLAGS) $^ - install: $(EXECS) install -d $(INSTDIR) diff --git a/utils/Makefile.freebsd b/utils/Makefile.freebsd index 6b9b1348..62e6cb17 100644 --- a/utils/Makefile.freebsd +++ b/utils/Makefile.freebsd @@ -8,7 +8,6 @@ CC = gcc LD = gcc EXECS = hxascdmp -# EXECS = hxascdmp sg_chk_asc MAN_PGS = MAN_PREF = man8 @@ -30,9 +29,6 @@ clean: hxascdmp: hxascdmp.o $(LD) -o $@ $(LDFLAGS) $@.o -sg_chk_asc: sg_chk_asc.o ../sg_lib.o ../sg_lib_data.o - $(LD) -o $@ $(LDFLAGS) $@.o ../sg_lib.o - install: $(EXECS) install -d $(INSTDIR) diff --git a/utils/Makefile.solaris b/utils/Makefile.solaris index b49115a0..075d0046 100644 --- a/utils/Makefile.solaris +++ b/utils/Makefile.solaris @@ -8,7 +8,6 @@ CC = gcc LD = gcc EXECS = hxascdmp -# EXECS = hxascdmp sg_chk_asc MAN_PGS = MAN_PREF = man8 @@ -30,9 +29,6 @@ clean: hxascdmp: hxascdmp.o $(LD) -o $@ $(LDFLAGS) $@.o -sg_chk_asc: sg_chk_asc.o ../sg_lib.o - $(LD) -o $@ $(LDFLAGS) $@.o ../sg_lib.o - install: $(EXECS) install -d $(INSTDIR) diff --git a/utils/README b/utils/README index ce2d6982..c4d1dc3d 100644 --- a/utils/README +++ b/utils/README @@ -5,11 +5,8 @@ This directory contains these utilities: the Unix "od" command. By default, it decodes 16 bytes per line with an ASCII interpretation to the right of each line. See its hxascdmp(1) man page. - - sg_chk_asc: utility decodes the SCSI additional sense code table - found at http://www.t10.org/lists/asc-num.txt and checks it - against the table found in sg_lib_data.c in the lib/ subdirectory. - It is designed to keep the table in sg_lib_data.c in "sync" with the - table at the t10.org web site. + - sg_chk_asc and tst_sg_lib: are no longer here, they have been moved + to the 'testing' directory (a sibling of this directory). By default, the Makefile only builds the hxascdmp utility. The 'Makefile' @@ -19,11 +16,5 @@ builds for FreeBSD (e.g. 'make -f Makefile.freebsd'); the in the Windows MinGW environment (e.g. msys shell); and 'Makefile.cygwin' builds in the Windows Cygwin environment. -To build sg_chk_asc the sg_lib.o and sg_lib_data.o files must be present -(i.e. compiled) in the lib/ subdirectory. One way to meet that requirement -is to execute './configure' in the main directory then 'cd lib ; make '. -Then return to this directory and do 'make sg_chk_asc'. - - Douglas Gilbert -30th March 2010 +4th November 2017 diff --git a/utils/sg_chk_asc.c b/utils/sg_chk_asc.c deleted file mode 100644 index cb30075d..00000000 --- a/utils/sg_chk_asc.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2006-2015 Douglas Gilbert. - * All rights reserved. - * Use of this source code is governed by a BSD-style - * license that can be found in the BSD_LICENSE file. - */ - -#include <unistd.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <getopt.h> -#include <ctype.h> -#include <errno.h> - -#include "sg_lib.h" - -/* A utility program for the Linux OS SCSI subsystem. - * - * This program takes a asc_ascq.txt file from www.t10.org and - * checks it against the additional sense codes held in the - * sg_lib.c file. - * The online version of the asc_ascq codes can be found at: - * http://www.t10.org/lists/asc-num.txt - */ - -static char * version_str = "1.05 20150105"; - - -#define MAX_LINE_LEN 1024 - - -static struct option long_options[] = { - {"help", 0, 0, 'h'}, - {"verbose", 0, 0, 'v'}, - {"version", 0, 0, 'V'}, - {0, 0, 0, 0}, -}; - -static void usage() -{ - fprintf(stderr, "Usage: " - "sg_chk_asc [--help] [--offset=POS] [--verbose] [--version]\n" - " <asc_ascq_file>\n" - " where:\n" - " --help|-h print out usage message\n" - " --offset=POS|-o POS line position in file where " - "text starts\n" - " origin 0 (def: 24 (was 25))\n" - " --verbose|-v increase verbosity\n" - " --version|-V print version string and exit\n\n" - "Checks asc/ascq codes in <asc_ascq_file> against the sg3_utils " - "library.\nThe additional sense code (asc_ascq) can be found at\n" - "www.t10.org/lists/asc-num.txt .\n" - ); - -} - -int main(int argc, char * argv[]) -{ - int k, j, res, c, num, len, asc, ascq; - FILE * fp; - int offset = 24; - int verbose = 0; - char file_name[256]; - char line[MAX_LINE_LEN]; - char b[MAX_LINE_LEN]; - char bb[MAX_LINE_LEN]; - char * cp; - int ret = 1; - - memset(file_name, 0, sizeof file_name); - memset(line, 0, sizeof file_name); - while (1) { - int option_index = 0; - - c = getopt_long(argc, argv, "ho:vV", long_options, - &option_index); - if (c == -1) - break; - - switch (c) { - case 'h': - case '?': - usage(); - return 0; - case 'o': - offset = sg_get_num(optarg); - if (offset < 0) { - fprintf(stderr, "bad argument to --offset\n"); - return 1; - } - break; - case 'v': - ++verbose; - break; - case 'V': - fprintf(stderr, "version: %s\n", version_str); - return 0; - default: - fprintf(stderr, "unrecognised switch code 0x%x ??\n", c); - usage(); - return 1; - } - } - if (optind < argc) { - if ('\0' == file_name[0]) { - strncpy(file_name, argv[optind], sizeof(file_name) - 1); - file_name[sizeof(file_name) - 1] = '\0'; - ++optind; - } - if (optind < argc) { - for (; optind < argc; ++optind) - fprintf(stderr, "Unexpected extra argument: %s\n", - argv[optind]); - usage(); - return 1; - } - } - - if (0 == file_name[0]) { - fprintf(stderr, "missing file name!\n"); - usage(); - return 1; - } - fp = fopen(file_name, "r"); - if (NULL == fp) { - fprintf(stderr, "open error: %s: %s\n", file_name, - safe_strerror(errno)); - return 1; - } - for (k = 0; (cp = fgets(line, sizeof(line) - 1, fp)); ++k) { - len = strlen(line); - if (len < 1) - continue; - if (! isdigit(line[0])) - continue; - num = sscanf(line, "%xh/%xh", &asc, &ascq); - if (1 == num) - ascq = -1; - if (num < 1) { - if (verbose) - fprintf(stderr, "Badly formed line number %d (num=%d)\n", - k + 1, num); - continue; - } - if (len < 26) - continue; -#if 0 -strncpy(b , line, sizeof(b) - 1); -b[sizeof(b) - 1] = '\0'; -num = strlen(b); -if (0xd == b[num - 2]) { - b[num - 2] = '\0'; - b[num - 1] = '\0'; -} -printf("\"%s\",\n", b); -#endif - strncpy(b , line + offset, sizeof(b) - 1); - b[sizeof(b) - 1] = '\0'; - num = strlen(b); - if (0xd == b[num - 2]) { - b[num - 2] = '\0'; - b[num - 1] = '\0'; - } - num = strlen(b); - for (j = 0; j < num; ++j) - b[j] = toupper(b[j]); - - bb[0] = '\0'; - if (ascq >= 0) { - cp = sg_get_asc_ascq_str(asc, ascq, sizeof(bb) - 1, bb); - if (NULL == cp) { - fprintf(stderr, "no entry for %x,%x : %s\n", asc, ascq, b); - continue; - } - num = strlen(cp); -// fprintf(stderr, "file: asc=%x acsq=%x strlen=%d %s\n", asc, ascq, num, -// cp); -// if (num < 20) -// continue; - if ((num > 6) && - ((0 == memcmp("ASC", cp, 3)) || - (0 == memcmp("vendor", cp, 6)))) { - fprintf(stderr, "%x,%x differ, ref: %s, sg_lib_data: " - "<missing>\n", asc, ascq, b); - continue; - } - if (num > 20) { - cp += 18; - num -= 18; - for (j = 0; j < num; ++j) - cp[j] = toupper(cp[j]); - } - if (0 != strcmp(b, cp)) - fprintf(stderr, "%x,%x differ, ref: %s, sg_lib_data: " - "%s\n", asc, ascq, b, cp); - } - } - if (NULL == cp) { - if (feof(fp)) { - if (verbose > 2) - fprintf(stderr, "EOF detected\n"); - } else - fprintf(stderr, "fgets: %s\n", safe_strerror(errno)); - } else - fprintf(stderr, "%s\n", line); - - res = fclose(fp); - if (EOF == res) { - fprintf(stderr, "close error: %s\n", safe_strerror(errno)); - return 1; - } - return ret; -} diff --git a/utils/tst_sg_lib.c b/utils/tst_sg_lib.c deleted file mode 100644 index 13be7ff8..00000000 --- a/utils/tst_sg_lib.c +++ /dev/null @@ -1,469 +0,0 @@ -/* - * Copyright (c) 2013-2016 Douglas Gilbert. - * All rights reserved. - * Use of this source code is governed by a BSD-style - * license that can be found in the BSD_LICENSE file. - */ - -#include <unistd.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <getopt.h> -#include <ctype.h> -#include <errno.h> -#define __STDC_FORMAT_MACROS 1 -#include <inttypes.h> - -#include "sg_lib.h" -#include "sg_unaligned.h" - -/* A utility program to test sg_libs string handling, specifically - * related to snprintf(). - * - */ - -static char * version_str = "1.04 20160503"; - - -#define MAX_LINE_LEN 1024 - - -static struct option long_options[] = { - {"dstrhex", no_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - {"leadin", required_argument, 0, 'l'}, - {"printf", no_argument, 0, 'p'}, - {"sense", no_argument, 0, 's'}, - {"unaligned", no_argument, 0, 'u'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0}, /* sentinel */ -}; - -static const unsigned char desc_sense_data1[] = { - /* unrec_err, excessive_writes, sdat_ovfl, additional_len=? */ - 0x72, 0x1, 0x3, 0x2, 0x80, 0x0, 0x0, 12+12+8+4+8+4+28, - /* Information: 0x11223344556677bb */ - 0x0, 0xa, 0x80, 0x0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xbb, - /* command specific: 0x3344556677bbccff */ - 0x1, 0xa, 0x0, 0x0, 0x33, 0x44, 0x55, 0x66, 0x77, 0xbb, 0xcc, 0xff, - /* sense key specific: SKSV=1, actual_count=257 (hex: 0x101) */ - 0x2, 0x6, 0x0, 0x0, 0x80, 0x1, 0x1, 0x0, - /* field replaceable code=0x45 */ - 0x3, 0x2, 0x0, 0x45, - /* another progress report indicator */ - 0xa, 0x6, 0x2, 0x1, 0x2, 0x0, 0x32, 0x01, - /* incorrect length indicator (ILI) */ - 0x5, 0x2, 0x0, 0x20, - /* user data degment referral */ - 0xb, 26, 0x1, 0x0, - 0,0,0,1, 0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8, - 0x1,0x2,0x3,0x4,0x55,0x6,0x7,0x8, - 2,0,0x12,0x34, - }; - -static const unsigned char desc_sense_data2[] = { - /* ill_req, inv fld in para list, additional_len=? */ - 0x72, 0x5, 0x26, 0x0, 0x0, 0x0, 0x0, 8+4, - /* sense key specific: SKSV=1, C/D*=0, bitp=7 bytep=34 */ - 0x2, 0x6, 0x0, 0x0, 0x8f, 0x0, 0x34, 0x0, - /* field replaceable code=0x45 */ - 0x3, 0x2, 0x0, 0x45, - }; - -static const unsigned char desc_sense_data3[] = { - /* medium err, vibration induced ..., additional_len=? */ - 0x72, 0x3, 0x9, 0x5, 0x0, 0x0, 0x0, 32+16, - /* 0xd: block dev: sense key specific: SKSV=1, retry_count=257, fru=0x45 - * info=0x1122334455, command_specific=0x1 */ - 0xd, 0x1e, 0xa0, 0x0, 0x80, 0x1, 0x1, 0x45, - 0x0, 0x0, 0x0, 0x11, 0x22, 0x33, 0x44, 0x55, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, - /* following sbc3 (standard) and sbc4r10 inconsistency; add padding */ - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - /* 0xe: reason: send_to_given+henceforth, lu, naa-5, 0x5333333000001f40 */ - 0xe, 0xe, 0x0, 0x1, 0x1, 0x3, 0x0, 0x8, - 0x53, 0x33, 0x33, 0x30, 0x0, 0x0, 0x1f, 0x40, - }; - -static const unsigned char desc_sense_data4[] = { - /* ill_req, inv fld in para list, additional_len=? */ - 0x72, 0x5, 0x26, 0x0, 0x0, 0x0, 0x0, 24, - /* Forwarded sense data, FSDT=0, sd_src=7, f_status=2 */ - 0xc, 22, 0x7, 0x2, - /* ill_req, inv fld in para list, additional_len=? */ - 0x72, 0x5, 0x26, 0x0, 0x0, 0x0, 0x0, 8+4, - /* sense key specific: SKSV=1, C/D*=0, bitp=7 bytep=34 */ - 0x2, 0x6, 0x0, 0x0, 0x8f, 0x0, 0x34, 0x0, - /* field replaceable code=0x45 */ - 0x3, 0x2, 0x0, 0x45, - }; - -static const unsigned char desc_sense_data5[] = { - /* no_sense, ATA info available */ - 0x72, 0x0, 0x0, 0x1d, 0x0, 0x0, 0x0, 14+14, - /* ATA descriptor extend=1 */ - 0x9, 0xc, 0x1, 0x0, 0x34, 0x12, 0x44, 0x11, - 0x55, 0x22, 0x66, 0x33, 0x1, 0x0, - /* ATA descriptor extend=0 */ - 0x9, 0xc, 0x0, 0x0, 0x34, 0x12, 0x44, 0x11, - 0x55, 0x22, 0x66, 0x33, 0x1, 0x0, - }; - -static const unsigned char desc_sense_data6[] = { - /* UA, req, subsidiary bindinganged */ - 0x72, 0x6, 0x3f, 0x1a, 0x0, 0x0, 0x0, 26+12+12, - /* 0xe: designator, reason: preferred admin lu, uuid */ - 0xe, 0x18, 0x0, 0x4, 0x1, 0xa, 0x0, 0x12, - 0x10, 0x0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, - 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, - 0xfe, 0xdc, - /* 0x0: Information(valid): lun */ - 0x0, 0xa, 0x80, 0x0, - 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - /* 0x1: Command specific: 0x1 */ - 0x1, 0xa, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, - }; - -static const char * leadin = NULL; - - -static void -usage() -{ - fprintf(stderr, - "Usage: tst_sg_lib [--dstrhex] [--help] [--leadin=STR] " - "[--printf]\n" - " [--sense] [--unaligned] [--verbose] " - "[--version]\n" - " where: --dstrhex|-d test dStrHex* variants\n" - " --help|-h print out usage message\n" - " --leadin=STR|-l STR every line output by --sense " - "should\n" - " be prefixed by STR\n" - " --printf|-p test library printf variants\n" - " --sense|-s test sense data handling\n" - " --unaligned|-u test unaligned data handling\n" - " --verbose|-v increase verbosity\n" - " --version|-V print version string and exit\n\n" - "Test various parts of sg_lib, see options. Sense data tests " - "overlap\nsomewhat with examples/sg_sense_test .\n" - ); - -} - -/* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1 - * then assume cp is pointing to a null char and do nothing. Returns number - * number of chars placed in cp excluding the trailing null char. So for - * cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len - * <= 0 the return value is 0 (and no chars are written to cp). */ -static int -my_snprintf(char * cp, int cp_max_len, const char * fmt, ...) -{ - va_list args; - int n; - - if (cp_max_len < 2) - return 0; - va_start(args, fmt); - n = vsnprintf(cp, cp_max_len, fmt, args); - va_end(args); - return (n < cp_max_len) ? n : (cp_max_len - 1); -} - - -int -main(int argc, char * argv[]) -{ - int k, c, n, len; - int do_dstrhex = 0; - int do_printf = 0; - int do_sense = 0; - int do_unaligned = 0; - int did_something = 0; - int verbose = 0; - int ret = 0; - char b[2048]; - char bb[256]; - - while (1) { - int option_index = 0; - - c = getopt_long(argc, argv, "dhl:psuvV", long_options, - &option_index); - if (c == -1) - break; - - switch (c) { - case 'd': - ++do_dstrhex; - break; - case 'h': - case '?': - usage(); - return 0; - case 'l': - leadin = optarg; - break; - case 'p': - ++do_printf; - break; - case 's': - ++do_sense; - break; - case 'u': - ++do_unaligned; - break; - case 'v': - ++verbose; - break; - case 'V': - fprintf(stderr, "version: %s\n", version_str); - return 0; - default: - fprintf(stderr, "unrecognised switch code 0x%x ??\n", c); - usage(); - return 1; - } - } - if (optind < argc) { - if (optind < argc) { - for (; optind < argc; ++optind) - fprintf(stderr, "Unexpected extra argument: %s\n", - argv[optind]); - usage(); - return 1; - } - } - - if (do_sense ) { - ++did_something; - printf("desc_sense_data test1:\n"); - sg_print_sense(leadin, desc_sense_data1, - (int)sizeof(desc_sense_data1), verbose); - printf("\n"); -#if 1 - printf("sg_get_sense_str(ds_data1):\n"); - sg_get_sense_str(leadin, desc_sense_data1, - sizeof(desc_sense_data1), verbose, sizeof(b), b); - printf("sg_get_sense_str: strlen(b)->%zd\n", strlen(b)); - printf("%s", b); - printf("\n"); -#endif - printf("desc_sense_data test2\n"); - sg_print_sense(leadin, desc_sense_data2, - (int)sizeof(desc_sense_data2), verbose); - printf("\n"); - printf("desc_sense block dev combo plus designator test3\n"); - sg_print_sense(leadin, desc_sense_data3, - (int)sizeof(desc_sense_data3), verbose); - printf("\n"); - printf("desc_sense forwarded sense test4\n"); - sg_print_sense(leadin, desc_sense_data4, - (int)sizeof(desc_sense_data4), verbose); - printf("\n"); - printf("desc_sense ATA Info test5\n"); - sg_print_sense(leadin, desc_sense_data5, - (int)sizeof(desc_sense_data5), verbose); - printf("\n"); - printf("desc_sense UA subsidiary binfing changed test6\n"); - sg_print_sense(leadin, desc_sense_data6, - (int)sizeof(desc_sense_data6), verbose); - printf("\n"); - printf("\n"); - } - - if (do_printf) { - ++did_something; - printf("Testing my_snprintf():\n"); - b[0] = '\0'; - len = sizeof(b); - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = -1; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 0; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 1; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 2; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 3; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 4; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 5; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 6; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - - b[0] = '\0'; - len = 7; - n = my_snprintf(b, len, "%s", "test"); - printf("my_snprintf(,%d,,\"test\") -> %d; strlen(b) -> %zd\n", - len, n, strlen(b)); - if (strlen(b) > 0) - printf("Resulting string: %s\n", b); - } - if (do_dstrhex) { - char b[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58}; - - ++did_something; - for (k = 0; k < 18; ++k) { - printf("k=%d:\n", k); - dStrHex(b, k, 0); - dStrHexStr(b, k, "dSHS_0: ", 0, sizeof(bb), bb); - printf("%s", bb); - dStrHex(b, k, 1); - dStrHexStr(b, k, "dSHS_1: ", 1, sizeof(bb), bb); - printf("%s", bb); - dStrHex(b, k, -1); - printf("\n"); - } - } - if (do_unaligned) { - uint16_t u16 = 0x55aa; - uint16_t u16r; - uint32_t u24 = 0x224488; - uint32_t u24r; - uint32_t u32 = 0x224488ff; - uint32_t u32r; - uint64_t u48 = 0x112233445566ULL; - uint64_t u48r; - uint64_t u64 = 0x1122334455667788ULL; - uint64_t u64r; - uint8_t u8[64]; - - ++did_something; - if (verbose) - memset(u8, 0, sizeof(u8)); - printf("u16=0x%" PRIx16 "\n", u16); - sg_put_unaligned_le16(u16, u8); - printf(" le16:\n"); - dStrHex((const char *)u8, verbose ? 10 : 2, -1); - u16r = sg_get_unaligned_le16(u8); - printf(" u16r=0x%" PRIx16 "\n", u16r); - sg_put_unaligned_be16(u16, u8); - printf(" be16:\n"); - dStrHex((const char *)u8, verbose ? 10 : 2, -1); - u16r = sg_get_unaligned_be16(u8); - printf(" u16r=0x%" PRIx16 "\n\n", u16r); - - printf("u24=0x%" PRIx32 "\n", u24); - sg_put_unaligned_le24(u24, u8); - printf(" le24:\n"); - dStrHex((const char *)u8, verbose ? 10 : 3, -1); - u24r = sg_get_unaligned_le24(u8); - printf(" u24r=0x%" PRIx32 "\n", u24r); - sg_put_unaligned_be24(u24, u8); - printf(" be24:\n"); - dStrHex((const char *)u8, verbose ? 10 : 3, -1); - u24r = sg_get_unaligned_be24(u8); - printf(" u24r=0x%" PRIx32 "\n\n", u24r); - - printf("u32=0x%" PRIx32 "\n", u32); - sg_put_unaligned_le32(u32, u8); - printf(" le32:\n"); - dStrHex((const char *)u8, verbose ? 10 : 4, -1); - u32r = sg_get_unaligned_le32(u8); - printf(" u32r=0x%" PRIx32 "\n", u32r); - sg_put_unaligned_be32(u32, u8); - printf(" be32:\n"); - dStrHex((const char *)u8, verbose ? 10 : 4, -1); - u32r = sg_get_unaligned_be32(u8); - printf(" u32r=0x%" PRIx32 "\n\n", u32r); - - printf("u48=0x%" PRIx64 "\n", u48); - sg_put_unaligned_le48(u48, u8); - printf(" le48:\n"); - dStrHex((const char *)u8, verbose ? 10 : 6, -1); - u48r = sg_get_unaligned_le48(u8); - printf(" u48r=0x%" PRIx64 "\n", u48r); - sg_put_unaligned_be48(u48, u8); - printf(" be48:\n"); - dStrHex((const char *)u8, verbose ? 10 : 6, -1); - u48r = sg_get_unaligned_be48(u8); - printf(" u48r=0x%" PRIx64 "\n\n", u48r); - - printf("u64=0x%" PRIx64 "\n", u64); - sg_put_unaligned_le64(u64, u8); - printf(" le64:\n"); - dStrHex((const char *)u8, verbose ? 10 : 8, -1); - u64r = sg_get_unaligned_le64(u8); - printf(" u64r=0x%" PRIx64 "\n", u64r); - sg_put_unaligned_be64(u64, u8); - printf(" be64:\n"); - dStrHex((const char *)u8, verbose ? 10 : 8, -1); - u64r = sg_get_unaligned_be64(u8); - printf(" u64r=0x%" PRIx64 "\n\n", u64r); - printf(" be[8]:\n"); - dStrHex((const char *)u8, verbose ? 10 : 8, -1); - u64r = sg_get_unaligned_be(8, u8); - printf(" u64r[8]=0x%" PRIx64 "\n\n", u64r); - printf(" le[8]:\n"); - u64r = sg_get_unaligned_le(8, u8); - printf(" u64r[8]=0x%" PRIx64 "\n\n", u64r); - - } - - if (0 == did_something) - printf("Looks like no tests done, check usage with '-h'\n"); - return ret; -} |