mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 15:32:59 +00:00
Merge pull request #12378 from davidgfnet/master
Moving more stuff from samples to tests
This commit is contained in:
commit
475213aa0a
@ -1,51 +1,58 @@
|
|||||||
include ../config.mk
|
|
||||||
|
|
||||||
OBJDIR = ../obj-unix
|
OBJDIR = ../obj-unix
|
||||||
|
|
||||||
TEST_UNIT_CFLAGS = $(CFLAGS) -Iinclude $(LDFLAGS) $(LIBCHECK_CFLAGS) -Werror -Wdeclaration-after-statement -fsanitize=address -fsanitize=undefined -ftest-coverage -fprofile-arcs -ggdb
|
TEST_UNIT_CFLAGS = $(CFLAGS) -Iinclude $(LDFLAGS) -lcheck $(LIBCHECK_CFLAGS) -Werror -Wdeclaration-after-statement -fsanitize=address -fsanitize=undefined -ftest-coverage -fprofile-arcs -ggdb
|
||||||
|
|
||||||
TEST_GENERIC_QUEUE = test_generic_queue
|
TEST_GENERIC_QUEUE = test/queues/test_generic_queue
|
||||||
TEST_GENERIC_QUEUE_SRC = test/queues/test_generic_queue.c queues/generic_queue.c
|
TEST_GENERIC_QUEUE_SRC = test/queues/test_generic_queue.c queues/generic_queue.c
|
||||||
TEST_GENERIC_QUEUE_FLAGS = $(CFLAGS) $(LDFLAGS) $(LIBCHECK_CFLAGS)
|
|
||||||
TEST_GENERIC_QUEUE_LIBS = $(LIBCHECK_LIBS)
|
|
||||||
|
|
||||||
$(TEST_GENERIC_QUEUE): $(TEST_GENERIC_QUEUE_SRC)
|
TEST_LINKED_LIST = test/lists/test_linked_list
|
||||||
$(CC) $(TEST_UNIT_CFLAGS) -o $(OBJDIR)/test/$@ $(TEST_GENERIC_QUEUE_SRC) $(TEST_GENERIC_QUEUE_LIBS)
|
|
||||||
|
|
||||||
TEST_LINKED_LIST = test_linked_list
|
|
||||||
TEST_LINKED_LIST_SRC = test/lists/test_linked_list.c lists/linked_list.c
|
TEST_LINKED_LIST_SRC = test/lists/test_linked_list.c lists/linked_list.c
|
||||||
TEST_LINKED_LIST_LIBS = $(LIBCHECK_LIBS)
|
|
||||||
|
|
||||||
$(TEST_LINKED_LIST): $(TEST_LINKED_LIST_SRC)
|
TEST_STDSTRING = test/string/test_stdstring
|
||||||
$(CC) $(TEST_UNIT_CFLAGS) -o $(OBJDIR)/test/$@ $(TEST_LINKED_LIST_SRC) $(TEST_LINKED_LIST_LIBS)
|
TEST_STDSTRING_SRC = test/string/test_stdstring.c string/stdstring.c encodings/encoding_utf.c \
|
||||||
|
compat/compat_strl.c
|
||||||
|
|
||||||
TEST_STDSTRING = test_stdstring
|
TEST_UTILS = test/utils/test_utils
|
||||||
TEST_STDSTRING_SRC = test/string/test_stdstring.c string/stdstring.c encodings/encoding_utf.c compat/compat_strl.c
|
TEST_UTILS_SRC = test/utils/test_utils.c utils/md5.c encodings/encoding_crc32.c \
|
||||||
TEST_STDSTRING_LIBS = $(LIBCHECK_LIBS)
|
streams/file_stream.c vfs/vfs_implementation.c file/file_path.c \
|
||||||
|
compat/compat_strl.c time/rtime.c string/stdstring.c encodings/encoding_utf.c
|
||||||
|
|
||||||
$(TEST_STDSTRING): $(TEST_STDSTRING_SRC)
|
TEST_HASH = test/hash/test_hash
|
||||||
$(CC) $(TEST_UNIT_CFLAGS) -o $(OBJDIR)/test/$@ $(TEST_STDSTRING_SRC) $(TEST_STDSTRING_LIBS)
|
TEST_HASH_SRC = test/hash/test_hash.c hash/lrc_hash.c \
|
||||||
|
streams/file_stream.c vfs/vfs_implementation.c file/file_path.c \
|
||||||
|
compat/compat_strl.c time/rtime.c string/stdstring.c encodings/encoding_utf.c
|
||||||
|
|
||||||
TEST_HASH = test_hash
|
all:
|
||||||
TEST_HASH_SRC = test/utils/test_hash.c utils/md5.c
|
# Build and execute tests in order, to avoid coverage file collision
|
||||||
TEST_HASH_LIBS = $(LIBCHECK_LIBS)
|
# string
|
||||||
|
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_STDSTRING_SRC) -o $(TEST_STDSTRING)
|
||||||
|
$(TEST_STDSTRING)
|
||||||
|
lcov -c -d . -o `dirname $(TEST_STDSTRING)`/coverage.info
|
||||||
|
# utils
|
||||||
|
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_UTILS_SRC) -o $(TEST_UTILS)
|
||||||
|
$(TEST_UTILS)
|
||||||
|
lcov -c -d . -o `dirname $(TEST_UTILS)`/coverage.info
|
||||||
|
# utils
|
||||||
|
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_HASH_SRC) -o $(TEST_HASH)
|
||||||
|
$(TEST_HASH)
|
||||||
|
lcov -c -d . -o `dirname $(TEST_HASH)`/coverage.info
|
||||||
|
# list
|
||||||
|
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_LINKED_LIST_SRC) -o $(TEST_LINKED_LIST)
|
||||||
|
$(TEST_LINKED_LIST)
|
||||||
|
lcov -c -d . -o `dirname $(TEST_LINKED_LIST)`/coverage.info
|
||||||
|
# queue
|
||||||
|
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_GENERIC_QUEUE_SRC) -o $(TEST_GENERIC_QUEUE)
|
||||||
|
$(TEST_GENERIC_QUEUE)
|
||||||
|
lcov -c -d . -o `dirname $(TEST_GENERIC_QUEUE)`/coverage.info
|
||||||
|
|
||||||
$(TEST_HASH): $(TEST_HASH_SRC)
|
lcov -o test/coverage.info \
|
||||||
$(CC) $(TEST_UNIT_CFLAGS) -o $(OBJDIR)/test/$@ $(TEST_HASH_SRC) $(TEST_HASH_LIBS)
|
-a test/utils/coverage.info \
|
||||||
|
-a test/string/coverage.info \
|
||||||
TESTS = $(TEST_GENERIC_QUEUE) $(TEST_LINKED_LIST) $(TEST_STDSTRING) $(TEST_HASH)
|
-a test/lists/coverage.info \
|
||||||
|
-a test/queues/coverage.info
|
||||||
ifeq ($(HAVE_LIBCHECK),1)
|
|
||||||
test-dir:
|
|
||||||
@mkdir -p $(OBJDIR)/test
|
|
||||||
|
|
||||||
test: test-dir $(TESTS)
|
|
||||||
@for t in $(TESTS); do \
|
|
||||||
LD_LIBRARY_PATH='$(LD_PATH)' $(OBJDIR)/test/$$t; \
|
|
||||||
done; \
|
|
||||||
lcov -c -d . -o test/coverage.info; \
|
|
||||||
genhtml -o test/coverage/ test/coverage.info
|
genhtml -o test/coverage/ test/coverage.info
|
||||||
else
|
|
||||||
test:
|
clean:
|
||||||
@echo "Cannot run unit tests. libcheck was not found."
|
rm -f *.gcda *.gcno
|
||||||
endif
|
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
TARGET := strl
|
|
||||||
|
|
||||||
CORE_DIR := .
|
|
||||||
LIBRETRO_COMM_DIR := ../../..
|
|
||||||
|
|
||||||
SOURCES_C := \
|
|
||||||
$(CORE_DIR)/strl_test.c \
|
|
||||||
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c
|
|
||||||
|
|
||||||
OBJS := $(SOURCES_C:.c=.o)
|
|
||||||
|
|
||||||
CFLAGS += -Wall -pedantic -std=gnu99 -I$(LIBRETRO_COMM_DIR)/include
|
|
||||||
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) -c -o $@ $< $(CFLAGS)
|
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
|
||||||
$(CC) -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(TARGET) $(OBJS)
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
@ -1,54 +0,0 @@
|
|||||||
/* Copyright (C) 2010-2020 The RetroArch team
|
|
||||||
*
|
|
||||||
* ---------------------------------------------------------------------------------------
|
|
||||||
* The following license statement only applies to this file (strl_test.c).
|
|
||||||
* ---------------------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge,
|
|
||||||
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
||||||
* to deal in the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
||||||
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <compat/strl.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
char s[128];
|
|
||||||
char *variable = "test1";
|
|
||||||
char *variable2 = "test2";
|
|
||||||
char *variable3 = "test3";
|
|
||||||
char *variable4 = "test4";
|
|
||||||
char *variable5 = "test5";
|
|
||||||
char *variable6 = "test6";
|
|
||||||
int ret = strlcpy(s, variable, sizeof(s));
|
|
||||||
ret = strlcat(s, " : ", sizeof(s));
|
|
||||||
ret = strlcat(s, variable2,sizeof(s));
|
|
||||||
ret = strlcat(s, " : ", sizeof(s));
|
|
||||||
ret = strlcat(s, variable3,sizeof(s));
|
|
||||||
ret = strlcat(s, " : ", sizeof(s));
|
|
||||||
ret = strlcat(s, variable4,sizeof(s));
|
|
||||||
ret = strlcat(s, " : ", sizeof(s));
|
|
||||||
ret = strlcat(s, variable5,sizeof(s));
|
|
||||||
ret = strlcat(s, " : ", sizeof(s));
|
|
||||||
ret = strlcat(s, variable6,sizeof(s));
|
|
||||||
|
|
||||||
fprintf(stderr, "[%d], %s\n", ret, s);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
compiler := gcc
|
|
||||||
extra_flags :=
|
|
||||||
use_neon := 0
|
|
||||||
release := release
|
|
||||||
EXE_EXT :=
|
|
||||||
|
|
||||||
ifeq ($(platform),)
|
|
||||||
platform = unix
|
|
||||||
ifeq ($(shell uname -a),)
|
|
||||||
platform = win
|
|
||||||
else ifneq ($(findstring MINGW,$(shell uname -a)),)
|
|
||||||
platform = win
|
|
||||||
else ifneq ($(findstring Darwin,$(shell uname -a)),)
|
|
||||||
platform = osx
|
|
||||||
arch = intel
|
|
||||||
ifeq ($(shell uname -p),powerpc)
|
|
||||||
arch = ppc
|
|
||||||
endif
|
|
||||||
else ifneq ($(findstring win,$(shell uname -a)),)
|
|
||||||
platform = win
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(compiler),gcc)
|
|
||||||
extra_rules_gcc := $(shell $(compiler) -dumpmachine)
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(findstring armv7,$(extra_rules_gcc)))
|
|
||||||
extra_flags += -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon
|
|
||||||
use_neon := 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(findstring hardfloat,$(extra_rules_gcc)))
|
|
||||||
extra_flags += -mfloat-abi=hard
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq (release,$(build))
|
|
||||||
extra_flags += -O2
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq (debug,$(build))
|
|
||||||
extra_flags += -O0 -g
|
|
||||||
endif
|
|
||||||
|
|
||||||
ldflags :=
|
|
||||||
|
|
||||||
EXE_EXT :=
|
|
||||||
ifeq ($(platform), unix)
|
|
||||||
else ifeq ($(platform), osx)
|
|
||||||
compiler := $(CC)
|
|
||||||
else
|
|
||||||
EXE_EXT = .exe
|
|
||||||
endif
|
|
||||||
|
|
||||||
PWD_DIR := .
|
|
||||||
LIBRETRO_COMM_DIR := ../..
|
|
||||||
CORE_DIR := $(LIBRETRO_COMM_DIR)/utils
|
|
||||||
|
|
||||||
CC := $(compiler)
|
|
||||||
CXX := $(subst CC,++,$(compiler))
|
|
||||||
flags := -I$(LIBRETRO_COMM_DIR)/include
|
|
||||||
asflags := $(extra_flags)
|
|
||||||
LDFLAGS :=
|
|
||||||
flags += -std=c99 -DMD5_BUILD_UTILITY -DSHA1_BUILD_UTILITY
|
|
||||||
|
|
||||||
ifeq (1,$(use_neon))
|
|
||||||
ASMFLAGS := -INEON/asm
|
|
||||||
asflags += -mfpu=neon
|
|
||||||
endif
|
|
||||||
|
|
||||||
DJB2_OBJS := $(CORE_DIR)/djb2.o
|
|
||||||
|
|
||||||
MD5_OBJS := $(CORE_DIR)/md5.o \
|
|
||||||
$(PWD_DIR)/md5_test.o
|
|
||||||
|
|
||||||
SHA1_OBJS := $(CORE_DIR)/sha1.o \
|
|
||||||
$(PWD_DIR)/sha1_main.o
|
|
||||||
|
|
||||||
CRC32_OBJS := $(PWD_DIR)/crc32.o \
|
|
||||||
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.o \
|
|
||||||
$(LIBRETRO_COMM_DIR)/compat/compat_strl.o \
|
|
||||||
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.o \
|
|
||||||
$(LIBRETRO_COMM_DIR)/streams/file_stream.o \
|
|
||||||
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.o \
|
|
||||||
$(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.o
|
|
||||||
|
|
||||||
UTILS := djb2$(EXE_EXT) md5$(EXE_EXT) sha1$(EXE_EXT) crc32$(EXE_EXT)
|
|
||||||
|
|
||||||
all: $(UTILS)
|
|
||||||
|
|
||||||
djb2$(EXE_EXT): $(DJB2_OBJS)
|
|
||||||
|
|
||||||
md5$(EXE_EXT): $(MD5_OBJS)
|
|
||||||
|
|
||||||
sha1$(EXE_EXT): $(SHA1_OBJS)
|
|
||||||
|
|
||||||
crc32$(EXE_EXT): $(CRC32_OBJS)
|
|
||||||
|
|
||||||
%.o: %.S
|
|
||||||
$(CC) -c -o $@ $(asflags) $(LDFLAGS) $(ASMFLAGS) $<
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) -c -o $@ $(flags) $<
|
|
||||||
|
|
||||||
$(UTILS):
|
|
||||||
$(CC) -o $@ $(ldflags) $(flags) $^
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(CORE_DIR)/*.o
|
|
||||||
rm -f $(UTILS)
|
|
||||||
|
|
||||||
strip:
|
|
||||||
strip -s $(UTILS)
|
|
@ -1,43 +0,0 @@
|
|||||||
/* gcc -O3 -o crc32 crc32.c -lz */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <encodings/crc32.h>
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
|
||||||
{
|
|
||||||
if (argc != 2 )
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Usage: crc32 <filename>\n" );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *file = fopen(argv[1], "rb");
|
|
||||||
|
|
||||||
if (file)
|
|
||||||
{
|
|
||||||
uint32_t crc = encoding_crc32(0L, NULL, 0 );
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
uint8_t buffer[16384];
|
|
||||||
|
|
||||||
int numread = fread((void*)buffer, 1, sizeof(buffer), file);
|
|
||||||
|
|
||||||
if (numread > 0)
|
|
||||||
crc = encoding_crc32( crc, buffer, numread );
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
printf("%08x\n", crc);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "Error opening input file: %s\n", strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
|
||||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
|
||||||
*
|
|
||||||
* Homepage:
|
|
||||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
|
||||||
*
|
|
||||||
* Author:
|
|
||||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
|
||||||
*
|
|
||||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
|
||||||
* claimed, and the software is hereby placed in the public domain.
|
|
||||||
* In case this attempt to disclaim copyright and place the software in the
|
|
||||||
* public domain is deemed null and void, then the software is
|
|
||||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
|
||||||
* general public under the following terms:
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted.
|
|
||||||
*
|
|
||||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
|
||||||
*
|
|
||||||
* (This is a heavily cut-down "BSD license".)
|
|
||||||
*
|
|
||||||
* This differs from Colin Plumb's older public domain implementation in that
|
|
||||||
* no exactly 32-bit integer data type is required (any 32-bit or wider
|
|
||||||
* unsigned integer data type will do), there's no compile-time endianness
|
|
||||||
* configuration, and the function prototypes match OpenSSL's. No code from
|
|
||||||
* Colin Plumb's implementation has been reused; this comment merely compares
|
|
||||||
* the properties of the two independent implementations.
|
|
||||||
*
|
|
||||||
* The primary goals of this implementation are portability and ease of use.
|
|
||||||
* It is meant to be fast, but not as fast as possible. Some known
|
|
||||||
* optimizations are not included to reduce source code size and avoid
|
|
||||||
* compile-time configuration.
|
|
||||||
*/
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <lrc_hash.h>
|
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
/* For each command line argument in turn:
|
|
||||||
** filename -- prints message digest and name of file
|
|
||||||
*/
|
|
||||||
int i;
|
|
||||||
MD5_CTX ctx;
|
|
||||||
FILE* file;
|
|
||||||
size_t numread;
|
|
||||||
char buffer[16384];
|
|
||||||
unsigned char result[16];
|
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
|
||||||
{
|
|
||||||
MD5_Init(&ctx);
|
|
||||||
file = fopen(argv[i], "rb");
|
|
||||||
|
|
||||||
if (file)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
numread = fread((void*)buffer, 1, sizeof(buffer), file);
|
|
||||||
|
|
||||||
if (numread)
|
|
||||||
{
|
|
||||||
MD5_Update(&ctx,(void*)buffer, numread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (numread);
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
MD5_Final(result, &ctx);
|
|
||||||
printf("%02x%02x%02x%02x%02x%02x%02x%02x"
|
|
||||||
"%02x%02x%02x%02x%02x%02x%02x%02x %s\n",
|
|
||||||
result[ 0 ], result[ 1 ], result[ 2 ], result[ 3 ],
|
|
||||||
result[ 4 ], result[ 5 ], result[ 6 ], result[ 7 ],
|
|
||||||
result[ 8 ], result[ 9 ], result[ 10 ], result[ 11 ],
|
|
||||||
result[ 12 ], result[ 13 ], result[ 14 ], result[ 15 ],
|
|
||||||
argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,189 +0,0 @@
|
|||||||
/*
|
|
||||||
* sha.cpp
|
|
||||||
*
|
|
||||||
* Copyright (C) 1998, 2009
|
|
||||||
* Paul E. Jones <paulej@packetizer.com>
|
|
||||||
* All Rights Reserved
|
|
||||||
*
|
|
||||||
*****************************************************************************
|
|
||||||
* $Id: sha.c 12 2009-06-22 19:34:25Z paulej $
|
|
||||||
*****************************************************************************
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* This utility will display the message digest (fingerprint) for
|
|
||||||
* the specified file(s).
|
|
||||||
*
|
|
||||||
* Portability Issues:
|
|
||||||
* None.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <io.h>
|
|
||||||
#endif
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <string/stdstring.h>
|
|
||||||
/*#include "sha1.h"*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Function prototype
|
|
||||||
*/
|
|
||||||
void usage(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* main
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* This is the entry point for the program
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* argc: [in]
|
|
||||||
* This is the count of arguments in the argv array
|
|
||||||
* argv: [in]
|
|
||||||
* This is an array of filenames for which to compute message
|
|
||||||
* digests
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* Nothing.
|
|
||||||
*
|
|
||||||
* Comments:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
typedef struct SHA1Context
|
|
||||||
{
|
|
||||||
unsigned Message_Digest[5]; /* Message Digest (output) */
|
|
||||||
|
|
||||||
unsigned Length_Low; /* Message length in bits */
|
|
||||||
unsigned Length_High; /* Message length in bits */
|
|
||||||
|
|
||||||
unsigned char Message_Block[64]; /* 512-bit message blocks */
|
|
||||||
int Message_Block_Index; /* Index into message block array */
|
|
||||||
|
|
||||||
int Computed; /* Is the digest computed? */
|
|
||||||
int Corrupted; /* Is the message digest corruped? */
|
|
||||||
} SHA1Context;
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
struct SHA1Context sha; /* SHA-1 context */
|
|
||||||
FILE *fp; /* File pointer for reading files*/
|
|
||||||
char c; /* Character read from file */
|
|
||||||
int i; /* Counter */
|
|
||||||
int reading_stdin; /* Are we reading standard in? */
|
|
||||||
int read_stdin = 0; /* Have we read stdin? */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check the program arguments and print usage information if -?
|
|
||||||
* or --help is passed as the first argument.
|
|
||||||
*/
|
|
||||||
if (argc > 1 && (string_is_equal(argv[1],"-?") ||
|
|
||||||
string_is_equal(argv[1],"--help")))
|
|
||||||
{
|
|
||||||
usage();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* For each filename passed in on the command line, calculate the
|
|
||||||
* SHA-1 value and display it.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < argc; i++)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* We start the counter at 0 to guarantee entry into the for
|
|
||||||
* loop. So if 'i' is zero, we will increment it now. If there
|
|
||||||
* is no argv[1], we will use STDIN below.
|
|
||||||
*/
|
|
||||||
if (i == 0)
|
|
||||||
i++;
|
|
||||||
|
|
||||||
if (argc == 1 || string_is_equal(argv[i],"-"))
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
setmode(fileno(stdin), _O_BINARY);
|
|
||||||
#endif
|
|
||||||
fp = stdin;
|
|
||||||
reading_stdin = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(fp = fopen(argv[i],"rb")))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"sha: unable to open file %s\n",
|
|
||||||
argv[i]);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
reading_stdin = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We do not want to read STDIN multiple times
|
|
||||||
*/
|
|
||||||
if (reading_stdin)
|
|
||||||
{
|
|
||||||
if (read_stdin)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
read_stdin = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset the SHA-1 context and process input
|
|
||||||
*/
|
|
||||||
SHA1Reset(&sha);
|
|
||||||
|
|
||||||
c = fgetc(fp);
|
|
||||||
while(!feof(fp))
|
|
||||||
{
|
|
||||||
SHA1Input(&sha, &c, 1);
|
|
||||||
c = fgetc(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!reading_stdin)
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
if (!SHA1Result(&sha))
|
|
||||||
{
|
|
||||||
fprintf(stderr,
|
|
||||||
"sha: could not compute message digest for %s\n",
|
|
||||||
reading_stdin?"STDIN":argv[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf( "%08X %08X %08X %08X %08X - %s\n",
|
|
||||||
sha.Message_Digest[0],
|
|
||||||
sha.Message_Digest[1],
|
|
||||||
sha.Message_Digest[2],
|
|
||||||
sha.Message_Digest[3],
|
|
||||||
sha.Message_Digest[4],
|
|
||||||
reading_stdin?"STDIN":argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* usage
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* This function will display program usage information to the
|
|
||||||
* user.
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* Nothing.
|
|
||||||
*
|
|
||||||
* Comments:
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void usage(void)
|
|
||||||
{
|
|
||||||
printf("usage: sha <file> [<file> ...]\n");
|
|
||||||
printf("\tThis program will display the message digest\n");
|
|
||||||
printf("\tfor files using the Secure Hashing Algorithm (SHA-1).\n");
|
|
||||||
}
|
|
86
libretro-common/test/hash/test_hash.c
Normal file
86
libretro-common/test/hash/test_hash.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/* Copyright (C) 2021 The RetroArch team
|
||||||
|
*
|
||||||
|
* ---------------------------------------------------------------------------------------
|
||||||
|
* The following license statement only applies to this file (test_stdstring.c).
|
||||||
|
* ---------------------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge,
|
||||||
|
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <lrc_hash.h>
|
||||||
|
|
||||||
|
#define SUITE_NAME "hash"
|
||||||
|
|
||||||
|
START_TEST (test_sha256)
|
||||||
|
{
|
||||||
|
char output[65];
|
||||||
|
sha256_hash(output, (uint8_t*)"abc", 3);
|
||||||
|
ck_assert(!strcmp(output,
|
||||||
|
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"));
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_sha1)
|
||||||
|
{
|
||||||
|
char output[41];
|
||||||
|
char tmpfile[512];
|
||||||
|
FILE *fd;
|
||||||
|
tmpnam(tmpfile);
|
||||||
|
fd = fopen(tmpfile, "wb");
|
||||||
|
ck_assert(fd != NULL);
|
||||||
|
fwrite("abc", 1, 3, fd);
|
||||||
|
fclose(fd);
|
||||||
|
sha1_calculate(tmpfile, output);
|
||||||
|
|
||||||
|
ck_assert(!strcmp(output,
|
||||||
|
"A9993E364706816ABA3E25717850C26C9CD0D89D"));
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_djb2)
|
||||||
|
{
|
||||||
|
ck_assert_uint_eq(djb2_calculate("retroarch"), 0xFADF3BCF);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
Suite *create_suite(void)
|
||||||
|
{
|
||||||
|
Suite *s = suite_create(SUITE_NAME);
|
||||||
|
|
||||||
|
TCase *tc_core = tcase_create("Core");
|
||||||
|
tcase_add_test(tc_core, test_sha256);
|
||||||
|
tcase_add_test(tc_core, test_sha1);
|
||||||
|
tcase_add_test(tc_core, test_djb2);
|
||||||
|
suite_add_tcase(s, tc_core);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int num_fail;
|
||||||
|
Suite *s = create_suite();
|
||||||
|
SRunner *sr = srunner_create(s);
|
||||||
|
srunner_run_all(sr, CK_NORMAL);
|
||||||
|
num_fail = srunner_ntests_failed(sr);
|
||||||
|
srunner_free(sr);
|
||||||
|
return (num_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
@ -1275,6 +1275,7 @@ Suite *create_suite(void)
|
|||||||
tcase_add_test(tc_core, test_linked_list_set_at_first);
|
tcase_add_test(tc_core, test_linked_list_set_at_first);
|
||||||
tcase_add_test(tc_core, test_linked_list_set_at_middle);
|
tcase_add_test(tc_core, test_linked_list_set_at_middle);
|
||||||
tcase_add_test(tc_core, test_linked_list_set_at_last);
|
tcase_add_test(tc_core, test_linked_list_set_at_last);
|
||||||
|
tcase_add_test(tc_core, test_linked_list_iterator_remove_null);
|
||||||
tcase_add_test(tc_core, test_linked_list_iterator_remove_first);
|
tcase_add_test(tc_core, test_linked_list_iterator_remove_first);
|
||||||
tcase_add_test(tc_core, test_linked_list_iterator_remove_middle);
|
tcase_add_test(tc_core, test_linked_list_iterator_remove_middle);
|
||||||
tcase_add_test(tc_core, test_linked_list_iterator_remove_last);
|
tcase_add_test(tc_core, test_linked_list_iterator_remove_last);
|
||||||
|
@ -211,6 +211,32 @@ START_TEST (test_strlcpy)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_strlcat)
|
||||||
|
{
|
||||||
|
char buf1[8];
|
||||||
|
buf1[0] = 'f';
|
||||||
|
buf1[1] = '\0';
|
||||||
|
ck_assert_uint_eq(10, strlcat(buf1, "ooooooooo", sizeof(buf1)));
|
||||||
|
ck_assert(!memcmp(buf1, "foooooo\0", 8));
|
||||||
|
ck_assert_uint_eq(13, strlcat(buf1, "123456", sizeof(buf1)));
|
||||||
|
ck_assert(!memcmp(buf1, "foooooo\0", 8));
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_strldup)
|
||||||
|
{
|
||||||
|
char buf1[8] = "foo";
|
||||||
|
char *tv1 = strldup(buf1, 16);
|
||||||
|
char *tv2 = strldup(buf1, 2);
|
||||||
|
ck_assert(tv1 != (char*)buf1);
|
||||||
|
ck_assert(tv2 != (char*)buf1);
|
||||||
|
ck_assert_uint_eq(strlen(tv2), 1);
|
||||||
|
ck_assert(tv2[0] == 'f' && tv2[1] == 0);
|
||||||
|
free(tv1);
|
||||||
|
free(tv2);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
START_TEST (test_utf8_conv_utf32)
|
START_TEST (test_utf8_conv_utf32)
|
||||||
{
|
{
|
||||||
uint32_t output[12];
|
uint32_t output[12];
|
||||||
@ -273,6 +299,8 @@ Suite *create_suite(void)
|
|||||||
tcase_add_test(tc_core, test_string_replacesubstr);
|
tcase_add_test(tc_core, test_string_replacesubstr);
|
||||||
tcase_add_test(tc_core, test_word_wrap);
|
tcase_add_test(tc_core, test_word_wrap);
|
||||||
tcase_add_test(tc_core, test_strlcpy);
|
tcase_add_test(tc_core, test_strlcpy);
|
||||||
|
tcase_add_test(tc_core, test_strlcat);
|
||||||
|
tcase_add_test(tc_core, test_strldup);
|
||||||
tcase_add_test(tc_core, test_utf8_conv_utf32);
|
tcase_add_test(tc_core, test_utf8_conv_utf32);
|
||||||
tcase_add_test(tc_core, test_utf16_conv);
|
tcase_add_test(tc_core, test_utf16_conv);
|
||||||
tcase_add_test(tc_core, test_utf8_util);
|
tcase_add_test(tc_core, test_utf8_util);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <utils/md5.h>
|
#include <utils/md5.h>
|
||||||
|
#include <encodings/crc32.h>
|
||||||
|
|
||||||
#define SUITE_NAME "hash"
|
#define SUITE_NAME "hash"
|
||||||
|
|
||||||
@ -55,12 +56,45 @@ START_TEST (test_md5)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_crc32)
|
||||||
|
{
|
||||||
|
char buf1[] = "retroarch";
|
||||||
|
char buf2[] = "12345678";
|
||||||
|
char buf3[] = "The quick brown fox jumps over the lazy dog";
|
||||||
|
uint32_t test1 = encoding_crc32(0, (uint8_t*)buf1, strlen(buf1));
|
||||||
|
uint32_t test2 = encoding_crc32(0, (uint8_t*)buf2, strlen(buf2));
|
||||||
|
uint32_t test3 = encoding_crc32(0, (uint8_t*)buf3, strlen(buf3));
|
||||||
|
ck_assert_uint_eq(0x3cae141a, test1);
|
||||||
|
ck_assert_uint_eq(0x9ae0daaf, test2);
|
||||||
|
ck_assert_uint_eq(0x414fa339, test3);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (test_crc32_file)
|
||||||
|
{
|
||||||
|
char tmpfile[512];
|
||||||
|
FILE *fd;
|
||||||
|
tmpnam(tmpfile);
|
||||||
|
fd = fopen(tmpfile, "wb");
|
||||||
|
ck_assert(fd != NULL);
|
||||||
|
fwrite("12345678", 1, 8, fd);
|
||||||
|
fclose(fd);
|
||||||
|
|
||||||
|
ck_assert_uint_eq(file_crc32(0, tmpfile), 0x9ae0daaf);
|
||||||
|
/* Error checking */
|
||||||
|
ck_assert_uint_eq(file_crc32(0, "/this/path/should/not/exist"), 0);
|
||||||
|
ck_assert_uint_eq(file_crc32(0, NULL), 0);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
Suite *create_suite(void)
|
Suite *create_suite(void)
|
||||||
{
|
{
|
||||||
Suite *s = suite_create(SUITE_NAME);
|
Suite *s = suite_create(SUITE_NAME);
|
||||||
|
|
||||||
TCase *tc_core = tcase_create("Core");
|
TCase *tc_core = tcase_create("Core");
|
||||||
tcase_add_test(tc_core, test_md5);
|
tcase_add_test(tc_core, test_md5);
|
||||||
|
tcase_add_test(tc_core, test_crc32);
|
||||||
|
tcase_add_test(tc_core, test_crc32_file);
|
||||||
suite_add_tcase(s, tc_core);
|
suite_add_tcase(s, tc_core);
|
||||||
|
|
||||||
return s;
|
return s;
|
@ -1,26 +0,0 @@
|
|||||||
/* public domain */
|
|
||||||
/* gcc -O3 -o djb2 djb2.c */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
static uint32_t djb2(const char* str)
|
|
||||||
{
|
|
||||||
const unsigned char* aux = (const unsigned char*)str;
|
|
||||||
uint32_t hash = 5381;
|
|
||||||
|
|
||||||
while (*aux)
|
|
||||||
hash = (hash << 5) + hash + *aux++;
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
|
||||||
printf( "0x%08xU: %s\n", djb2( argv[ i ] ), argv[ i ] );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user