Skip to content
Commits on Source (8)
......@@ -475,7 +475,8 @@ sockaddr_dump(const sockaddr_u *psau)
static void
print_interface(const endpt *iface, const char *pfx, const char *sfx)
{
printf("%sinterface #%d: fd=%d, bfd=%d, name=%s, flags=0x%x, ifindex=%u, sin=%s",
printf("%sinterface #%u: fd=%d, bfd=%d, name=%s, "
"flags=0x%x, ifindex=%u, sin=%s",
pfx,
iface->ifnum,
iface->fd,
......@@ -758,7 +759,9 @@ remove_interface(
if (ep->fd != INVALID_SOCKET) {
msyslog(LOG_INFO,
"Deleting interface #%d %s, %s#%d, interface stats: received=%ld, sent=%ld, dropped=%ld, active_time=%ld secs",
"Deleting interface #%u %s, %s#%d, interface stats: "
"received=%ld, sent=%ld, dropped=%ld, "
"active_time=%lu secs",
ep->ifnum,
ep->name,
socktoa(&ep->sin),
......@@ -773,7 +776,8 @@ remove_interface(
if (ep->bfd != INVALID_SOCKET) {
msyslog(LOG_INFO,
"stop listening for broadcasts to %s on interface #%d %s",
"stop listening for broadcasts to %s "
"on interface #%u %s",
socktoa(&ep->bcast), ep->ifnum, ep->name);
close_and_delete_fd_from_list(ep->bfd);
ep->bfd = INVALID_SOCKET;
......@@ -795,7 +799,7 @@ log_listen_address(
endpt * ep
)
{
msyslog(LOG_INFO, "%s on %d %s %s",
msyslog(LOG_INFO, "%s on %u %s %s",
(ep->ignore_packets)
? "Listen and drop"
: "Listen normally",
......@@ -961,7 +965,7 @@ action_text(
default:
t = "ERROR"; /* quiet uninit warning */
DPRINTF(1, ("fatal: unknown nic_rule_action %d\n",
DPRINTF(1, ("fatal: unknown nic_rule_action %u\n",
action));
NTP_ENSURE(0);
break;
......@@ -1762,7 +1766,7 @@ create_interface(
if (INVALID_SOCKET == iface->fd
&& INVALID_SOCKET == iface->bfd) {
msyslog(LOG_ERR, "unable to create socket on %s (%d) for %s#%d",
msyslog(LOG_ERR, "unable to create socket on %s (%u) for %s#%d",
iface->name,
iface->ifnum,
socktoa((&iface->sin)),
......@@ -2022,8 +2026,9 @@ open_socket(
if (setsockopt(fd, IPPROTO_IP, IP_TOS, (char*)&qos,
sizeof(qos)))
msyslog(LOG_ERR,
"setsockopt IP_TOS (%02x) fails on address %s: %m",
qos, socktoa(addr));
"setsockopt IP_TOS (%02x) fails on "
"address %s: %m",
(unsigned)qos, socktoa(addr));
if (bcast)
socket_broadcast_enable(interf, fd, addr);
}
......@@ -2035,9 +2040,9 @@ open_socket(
#ifdef IPV6_TCLASS
if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, (char*)&qos,
sizeof(qos)))
msyslog(LOG_ERR,
"setsockopt IPV6_TCLASS (%02x) fails on address %s: %m",
qos, socktoa(addr));
msyslog(LOG_ERR, "setsockopt IPV6_TCLASS (%02x) "
"fails on address %s: %m",
(unsigned)qos, socktoa(addr));
#endif /* IPV6_TCLASS */
if (isc_net_probe_ipv6only_bool()
&& setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
......@@ -2092,7 +2097,7 @@ open_socket(
enable_packetstamps(fd);
#endif /* USE_PACKET_TIMESTAMP */
DPRINTF(4, ("bind(%d) AF_INET%s, addr %s%%%d#%d, flags 0x%x\n",
DPRINTF(4, ("bind(%d) AF_INET%s, addr %s%%%u#%d, flags 0x%x\n",
fd, IS_IPV6(addr) ? "6" : "", socktoa(addr),
SCOPE(addr), SRCPORT(addr), interf->flags));
......@@ -2102,7 +2107,8 @@ open_socket(
#ifdef F_GETFL
/* F_GETFL may not be defined if the underlying OS isn't really Unix */
DPRINTF(4, ("flags for fd %d: 0x%x\n", fd, fcntl(fd, F_GETFL, 0)));
DPRINTF(4, ("flags for fd %d: 0x%x\n", fd,
(unsigned)fcntl(fd, F_GETFL, 0)));
#endif
return fd;
......@@ -2659,7 +2665,7 @@ findinterface(
iface = ANY_INTERFACE_CHOOSE(addr);
} else
DPRINTF(4, ("Found interface #%d %s for address %s\n",
DPRINTF(4, ("Found interface #%u %s for address %s\n",
iface->ifnum, iface->name, socktoa(addr)));
return iface;
......@@ -2994,7 +3000,7 @@ findbcastinter(
socktoa(addr)));
iface = ANY_INTERFACE_CHOOSE(addr);
} else {
DPRINTF(4, ("Found bcast-/mcast- interface index #%d %s\n",
DPRINTF(4, ("Found bcast-/mcast- interface index #%u %s\n",
iface->ifnum, iface->name));
}
......@@ -3194,7 +3200,8 @@ delete_interface_from_list(
if (unlinked == NULL)
break;
DPRINTF(4, ("Deleted addr %s for interface #%d %s from list of addresses\n",
DPRINTF(4, ("Deleted addr %s for interface #%u %s "
"from list of addresses\n",
socktoa(&unlinked->addr), iface->ifnum,
iface->name));
free(unlinked);
......
......@@ -198,8 +198,8 @@ static void
sync_status(const char *what, int ostatus, int nstatus)
{
char obuf[256], nbuf[256], tbuf[1024];
snprintf(obuf, sizeof(obuf), "%04x", ostatus);
snprintf(nbuf, sizeof(nbuf), "%04x", nstatus);
snprintf(obuf, sizeof(obuf), "%04x", (unsigned)ostatus);
snprintf(nbuf, sizeof(nbuf), "%04x", (unsigned)nstatus);
snprintf(tbuf, sizeof(tbuf), "%s status: %s -> %s", what, obuf, nbuf);
report_event(EVNT_KERN, NULL, tbuf);
}
......@@ -255,9 +255,10 @@ ntp_adjtime_error_handler(
case -1:
switch (saved_errno) {
case EFAULT:
msyslog(LOG_ERR, "%s: %s line %d: invalid struct timex pointer: 0x%lx",
msyslog(LOG_ERR, "%s: %s line %d: invalid "
"struct timex pointer: 0x%lx",
caller, file_name(), line,
(long)((void *)ptimex)
(long unsigned)((void *)ptimex)
);
break;
case EINVAL:
......@@ -403,7 +404,7 @@ or, from ntp_adjtime():
report_event(EVNT_KERN, NULL,
"no PPS signal");
DPRINTF(1, ("kernel loop status %#x (%s)\n",
ptimex->status, des));
(unsigned)ptimex->status, des));
/*
* This code may be returned when ntp_adjtime() has just
* been called for the first time, quite a while after
......@@ -419,7 +420,7 @@ or, from ntp_adjtime():
* msyslog(LOG_INFO, "kernel reports time synchronization lost");
*/
msyslog(LOG_INFO, "kernel reports TIME_ERROR: %#x: %s",
ptimex->status, des);
(unsigned)ptimex->status, des);
break;
#else
# warning TIME_ERROR is not defined
......
......@@ -1349,7 +1349,7 @@ peer_clear(
#ifdef DEBUG
if (debug)
printf(
"peer_clear: at %ld next %ld associd %d refid %s\n",
"peer_clear: at %lu next %lu associd %d refid %s\n",
current_time, peer->nextdate, peer->associd,
ident);
#endif
......@@ -2192,7 +2192,7 @@ peer_xmit(
#ifdef DEBUG
if (debug)
printf("transmit: at %ld %s->%s mode %d len %zu\n",
printf("transmit: at %lu %s->%s mode %d len %zu\n",
current_time, peer->dstadr ?
socktoa(&peer->dstadr->sin) : "-",
socktoa(&peer->srcadr), peer->hmode, sendlen);
......@@ -2232,7 +2232,7 @@ peer_xmit(
peer->throttle += (1 << peer->minpoll) - 2;
#ifdef DEBUG
if (debug)
printf("transmit: at %ld %s->%s mode %d keyid %08x len %zd\n",
printf("transmit: at %lu %s->%s mode %d keyid %08x len %zu\n",
current_time, peer->dstadr ?
socktoa(&peer->dstadr->sin) : "-",
socktoa(&peer->srcadr), peer->hmode, xkeyid, sendlen);
......@@ -2379,7 +2379,7 @@ fast_xmit(
#ifdef DEBUG
if (debug)
printf(
"transmit: at %ld %s->%s mode %d len %zd\n",
"transmit: at %lu %s->%s mode %d len %zu\n",
current_time, socktoa(&rbufp->dstadr->sin),
socktoa(&rbufp->recv_srcadr), xmode, sendlen);
#endif
......@@ -2401,7 +2401,7 @@ fast_xmit(
#ifdef DEBUG
if (debug)
printf(
"transmit: at %ld %s->%s mode %d keyid %08x len %zd\n",
"transmit: at %lu %s->%s mode %d keyid %08x len %zu\n",
current_time, socktoa(&rbufp->dstadr->sin),
socktoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen);
#endif
......@@ -2485,7 +2485,7 @@ pool_xmit(
pool->throttle += (1 << pool->minpoll) - 2;
#ifdef DEBUG
if (debug)
printf("transmit: at %ld %s->%s pool\n",
printf("transmit: at %lu %s->%s pool\n",
current_time, latoa(lcladr), socktoa(rmtadr));
#endif
msyslog(LOG_INFO, "Soliciting pool server %s", socktoa(rmtadr));
......
......@@ -188,13 +188,16 @@ getgroup:
}
if (group) {
if (0 != setgroups(1, &sw_gid)) {
msyslog(LOG_ERR, "setgroups(1, %d) failed: %m", sw_gid);
msyslog(LOG_ERR, "setgroups(1, %u) failed: %m",
sw_gid);
exit (-1);
}
}
else if (pw)
if (0 != initgroups(pw->pw_name, (gid_t)pw->pw_gid)) {
msyslog(LOG_ERR, "initgroups(<%s>, %d) filed: %m", pw->pw_name, pw->pw_gid);
msyslog(LOG_ERR,
"initgroups(<%s>, %u) filed: %m",
pw->pw_name, pw->pw_gid);
exit (-1);
}
if (user && setuid(sw_uid)) {
......
......@@ -416,8 +416,10 @@ check_leapsec(
} else {
int fired = leapsec_query(&lsdata, now);
DPRINTF(1, ("*** leapsec_query: fired %i, now %lli (0x%llX), tai_diff %i, ddist %u\n",
fired, (long long)now, (long long)now, lsdata.tai_diff, lsdata.ddist));
DPRINTF(1, ("*** leapsec_query: fired %i, now %lli (0x%llX), "
"tai_diff %i, ddist %u\n",
fired, (long long)now, (long long unsigned)now,
lsdata.tai_diff, lsdata.ddist));
#ifdef ENABLE_LEAP_SMEAR
leap_smear.in_progress = false;
leap_smear.doffset = 0.0;
......
......@@ -406,8 +406,8 @@ jjy_start ( int unit, struct peer *peer )
#ifdef DEBUG
if ( debug ) {
printf( "refclock_jjy.c : jjy_start : %s mode=%d dev=%s unit=%d\n",
socktoa(&peer->srcadr), peer->ttl, DEVICE, unit ) ;
printf("refclock_jjy.c: jjy_start: %s mode=%u dev=%s unit=%d\n",
socktoa(&peer->srcadr), peer->ttl, DEVICE, unit ) ;
}
#endif
......@@ -432,7 +432,8 @@ jjy_start ( int unit, struct peer *peer )
/* Set up the device name */
snprintf( sDeviceName, sizeof(sDeviceName), DEVICE, unit ) ;
snprintf( sLog, sizeof(sLog), "subtype=%d dev=%s", peer->ttl, sDeviceName ) ;
snprintf(sLog, sizeof(sLog), "subtype=%u dev=%s",
peer->ttl, sDeviceName ) ;
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_JJY, sLog ) ;
/*
......@@ -465,16 +466,18 @@ jjy_start ( int unit, struct peer *peer )
if ( 101 <= peer->ttl && peer->ttl <= 180 ) {
rc = jjy_start_telephone ( unit, peer, up ) ;
} else {
msyslog ( LOG_ERR, "JJY receiver [ %s subtype %d ] : Unsupported mode",
socktoa(&peer->srcadr), peer->ttl ) ;
free ( (void*) up ) ;
return false ;
msyslog (LOG_ERR,
"JJY receiver [ %s subtype %u ] : Unsupported mode",
socktoa(&peer->srcadr), peer->ttl ) ;
free ( (void*) up ) ;
return false ;
}
}
if ( rc != 0 ) {
msyslog ( LOG_ERR, "JJY receiver [ %s subtype %d ] : Initialize error",
socktoa(&peer->srcadr), peer->ttl ) ;
msyslog(LOG_ERR,
"JJY receiver [ %s subtype %u ] : Initialize error",
socktoa(&peer->srcadr), peer->ttl ) ;
free ( (void*) up ) ;
return false ;
}
......@@ -539,7 +542,8 @@ jjy_shutdown ( int unit, struct peer *peer )
free ( up ) ;
}
snprintf( sLog, sizeof(sLog), "JJY stopped. unit=%d subtype=%d", unit, peer->ttl ) ;
snprintf(sLog, sizeof(sLog), "JJY stopped. unit=%d subtype=%u",
unit, peer->ttl);
record_clock_stats(peer, sLog ) ;
}
......@@ -600,7 +604,7 @@ jjy_receive ( struct recvbuf *rbufp )
printf( "\nrefclock_jjy.c : %s : Len=%d ", sFunctionName, pp->lencode ) ;
for ( i = 0 ; i < pp->lencode ; i ++ ) {
if ( iscntrl( pp->a_lastcode[i] & 0x7F ) ) {
printf( "<x%02X>", pp->a_lastcode[i] & 0xFF ) ;
printf("<x%02X>", (unsigned)(pp->a_lastcode[i] & 0xFF));
} else {
printf( "%c", pp->a_lastcode[i] ) ;
}
......@@ -873,7 +877,7 @@ jjy_poll ( int unit, struct peer *peer )
sReach[7] = 0 ; /* This poll */
sReach[8] = 0 ;
snprintf( sLog, sizeof(sLog), "polls=%ld reach=%s", pp->polls, sReach ) ;
snprintf(sLog, sizeof(sLog), "polls=%lu reach=%s", pp->polls, sReach);
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ATTENTION, sLog ) ;
up->iProcessState = JJY_PROCESS_STATE_POLL ;
......@@ -1347,8 +1351,10 @@ jjy_poll_tristate_jjy01 ( int unit, struct peer *peer )
#ifdef DEBUG
if ( debug ) {
printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n",
sFunctionName, pp->sloppyclockflag, CLK_FLAG1,
printf ("%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X "
"up->iLineCount=%d\n",
sFunctionName, pp->sloppyclockflag,
(unsigned)CLK_FLAG1,
up->iLineCount ) ;
}
#endif
......@@ -1636,9 +1642,11 @@ jjy_receive_echokeisokuki_lt2000 ( struct recvbuf *rbufp )
ibcc1 = 0x30 | ( ( ibcc >> 4 ) & 0xF ) ;
ibcc2 = 0x30 | ( ( ibcc ) & 0xF ) ;
if ( pBuf[13] != ibcc1 || pBuf[14] != ibcc2 ) {
snprintf( sErr, sizeof(sErr)-1, " BCC error : Recv=%02X,%02X / Calc=%02X,%02X ",
pBuf[13] & 0xFF, pBuf[14] & 0xFF,
ibcc1, ibcc2 ) ;
snprintf(sErr, sizeof(sErr)-1,
" BCC error : Recv=%02X,%02X / Calc=%02X,%02X ",
(unsigned)(pBuf[13] & 0xFF),
(unsigned)(pBuf[14] & 0xFF),
(unsigned)ibcc1, (unsigned)ibcc2);
snprintf( sLog, sizeof(sLog)-1, JJY_CLOCKSTATS_MESSAGE_INVALID_REPLY,
sErr ) ;
jjy_write_clockstats( peer, JJY_CLOCKSTATS_MARK_ERROR, sLog ) ;
......@@ -2240,8 +2248,10 @@ jjy_poll_tristate_gpsclock01 ( int unit, struct peer *peer )
#ifdef DEBUG
if ( debug ) {
printf ( "%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X up->iLineCount=%d\n",
sFunctionName, pp->sloppyclockflag, CLK_FLAG1,
printf("%s (refclock_jjy.c) : flag1=%X CLK_FLAG1=%X "
"up->iLineCount=%d\n",
sFunctionName, pp->sloppyclockflag,
(unsigned)CLK_FLAG1,
up->iLineCount ) ;
}
#endif
......@@ -3907,7 +3917,9 @@ modem_receive ( struct recvbuf *rbufp )
iCopyLen = iLen <= (int)sizeof(sResp)-1 ?
(size_t)iLen : sizeof(sResp) - 1U;
strlcpy( sResp, pBuf, sizeof(sResp) ) ;
printf ( "refclock_jjy.c : modem_receive : iLen=%zd pBuf=[%s] iModemEvent=%d\n", iCopyLen, sResp, up->iModemEvent ) ;
printf( "refclock_jjy.c : modem_receive : iLen=%zu "
"pBuf=[%s] iModemEvent=%d\n",
iCopyLen, sResp, up->iModemEvent ) ;
}
#endif
modem_control ( peer, pp, up ) ;
......@@ -4530,7 +4542,7 @@ printableString ( char *sOutput, int iOutputLen, const char *sInput, int iInputL
if ( j + n + 1 >= OutputLen )
break ;
snprintf( sOutput + j, OutputLen - j, "<x%X>",
sInput[i] & 0xFF ) ;
(unsigned)(sInput[i] & 0xFF) ) ;
}
j += n ;
}
......
This diff is collapsed.
This diff is collapsed.
//- Copyright (c) 2010 James Grenning and Contributed to Unity Project
/* ==========================================
Unity Project - A Test Framework for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
SPDX-License-Identifier: MIT
========================================== */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
* ==========================================
* Unity Project - A Test Framework for C
* Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
* [Released under MIT License. Please refer to license.txt for details]
* ========================================== */
#include "unity_fixture.h"
#include "unity_internals.h"
#include <string.h>
UNITY_FIXTURE_T UnityFixture;
//If you decide to use the function pointer approach.
int (*outputChar)(int) = putchar;
struct UNITY_FIXTURE_T UnityFixture;
int verbose = 0;
/* If you decide to use the function pointer approach.
* Build with -D UNITY_OUTPUT_CHAR=outputChar and include <stdio.h>
* int (*outputChar)(int) = putchar; */
void setUp(void);
void tearDown(void);
#if !defined(UNITY_WEAK_ATTRIBUTE) && !defined(UNITY_WEAK_PRAGMA)
void setUp(void) { /*does nothing*/ }
void tearDown(void) { /*does nothing*/ }
#endif
static void announceTestRun(unsigned int runNumber)
{
UnityPrint("Unity test run ");
UnityPrintNumber(runNumber+1);
UnityPrintNumberUnsigned(runNumber+1);
UnityPrint(" of ");
UnityPrintNumber(UnityFixture.RepeatCount);
UNITY_OUTPUT_CHAR('\n');
UnityPrintNumberUnsigned(UnityFixture.RepeatCount);
UNITY_PRINT_EOL();
}
int UnityMain(int argc, const char* argv[], void (*runAllTests)(void))
......@@ -45,14 +41,14 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void))
UnityBegin(argv[0]);
announceTestRun(r);
runAllTests();
UNITY_OUTPUT_CHAR('\n');
if (!UnityFixture.Verbose) UNITY_PRINT_EOL();
UnityEnd();
}
return UnityFailureCount();
return (int)Unity.TestFailures;
}
static int selected(const char * filter, const char * name)
static int selected(const char* filter, const char* name)
{
if (filter == 0)
return 1;
......@@ -69,35 +65,34 @@ static int groupSelected(const char* group)
return selected(UnityFixture.GroupFilter, group);
}
static void runTestCase(void)
{
}
void UnityTestRunner(unityfunction* setup,
unityfunction* testBody,
unityfunction* teardown,
const char * printableName,
const char * group,
const char * name,
const char * file, int line)
unityfunction* testBody,
unityfunction* teardown,
const char* printableName,
const char* group,
const char* name,
const char* file,
unsigned int line)
{
if (testSelected(name) && groupSelected(group))
{
Unity.CurrentTestFailed = 0;
Unity.TestFile = file;
Unity.CurrentTestName = printableName;
Unity.CurrentTestLineNumber = (_U_UINT)line;
Unity.CurrentTestLineNumber = line;
if (!UnityFixture.Verbose)
UNITY_OUTPUT_CHAR('.');
else
{
UnityPrint(printableName);
#ifndef UNITY_REPEAT_TEST_NAME
Unity.CurrentTestName = NULL;
#endif
}
Unity.NumberOfTests++;
UnityMalloc_StartTest();
UnityPointer_Init();
runTestCase();
if (TEST_PROTECT())
{
setup();
......@@ -117,24 +112,25 @@ void UnityTestRunner(unityfunction* setup,
}
}
void UnityIgnoreTest(const char * printableName, const char * group, const char * name)
void UnityIgnoreTest(const char* printableName, const char* group, const char* name)
{
if (testSelected(name) && groupSelected(group))
if (testSelected(name) && groupSelected(group))
{
Unity.NumberOfTests++;
Unity.CurrentTestIgnored = 1;
Unity.TestIgnores++;
if (!UnityFixture.Verbose)
UNITY_OUTPUT_CHAR('!');
else
{
UnityPrint(printableName);
UnityConcludeFixtureTest();
UNITY_PRINT_EOL();
}
}
}
//-------------------------------------------------
//Malloc and free stuff
//
/*------------------------------------------------- */
/* Malloc and free stuff */
#define MALLOC_DONT_FAIL -1
static int malloc_count;
static int malloc_fail_countdown = MALLOC_DONT_FAIL;
......@@ -150,7 +146,7 @@ void UnityMalloc_EndTest(void)
malloc_fail_countdown = MALLOC_DONT_FAIL;
if (malloc_count != 0)
{
TEST_FAIL_MESSAGE("This test leaks!");
UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "This test leaks!");
}
}
......@@ -159,131 +155,163 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown)
malloc_fail_countdown = countdown;
}
#ifdef malloc
/* These definitions are always included from unity_fixture_malloc_overrides.h */
/* We undef to use them or avoid conflict with <stdlib.h> per the C standard */
#undef malloc
#endif
#ifdef free
#undef free
#endif
#ifdef calloc
#undef calloc
#endif
#ifdef realloc
#undef realloc
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
static unsigned char unity_heap[UNITY_INTERNAL_HEAP_SIZE_BYTES];
static size_t heap_index;
#else
#include <stdlib.h>
#endif
typedef struct GuardBytes
{
size_t size;
char guard[sizeof(size_t)];
size_t guard_space;
} Guard;
static const char * end = "END";
static const char end[] = "END";
void * unity_malloc(size_t size)
void* unity_malloc(size_t size)
{
char* mem;
Guard* guard;
size_t total_size = size + sizeof(Guard) + sizeof(end);
if (malloc_fail_countdown != MALLOC_DONT_FAIL)
{
if (malloc_fail_countdown == 0)
return 0;
return NULL;
malloc_fail_countdown--;
}
if (size == 0) return NULL;
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
if (heap_index + total_size > UNITY_INTERNAL_HEAP_SIZE_BYTES)
{
guard = NULL;
}
else
{
guard = (Guard*)&unity_heap[heap_index];
heap_index += total_size;
}
#else
guard = (Guard*)UNITY_FIXTURE_MALLOC(total_size);
#endif
if (guard == NULL) return NULL;
malloc_count++;
guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4);
guard->size = size;
guard->guard_space = 0;
mem = (char*)&(guard[1]);
memcpy(&mem[size], end, strlen(end) + 1);
memcpy(&mem[size], end, sizeof(end));
return (void*)mem;
}
static int isOverrun(void * mem)
static int isOverrun(void* mem)
{
Guard* guard = (Guard*)mem;
char* memAsChar = (char*)mem;
guard--;
return strcmp(&memAsChar[guard->size], end) != 0;
return guard->guard_space != 0 || strcmp(&memAsChar[guard->size], end) != 0;
}
static void release_memory(void * mem)
static void release_memory(void* mem)
{
Guard* guard = (Guard*)mem;
guard--;
malloc_count--;
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
if (mem == unity_heap + heap_index - guard->size - sizeof(end))
{
heap_index -= (guard->size + sizeof(Guard) + sizeof(end));
}
#else
UNITY_FIXTURE_FREE(guard);
#endif
}
void unity_free(void * mem)
void unity_free(void* mem)
{
int overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0;
int overrun;
if (mem == NULL)
{
return;
}
overrun = isOverrun(mem);
release_memory(mem);
if (overrun)
{
TEST_FAIL_MESSAGE("Buffer overrun detected during free()");
UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during free()");
}
}
void* unity_calloc(size_t num, size_t size)
{
void* mem = unity_malloc(num * size);
memset(mem, 0, num*size);
if (mem == NULL) return NULL;
memset(mem, 0, num * size);
return mem;
}
void* unity_realloc(void * oldMem, size_t size)
void* unity_realloc(void* oldMem, size_t size)
{
Guard* guard = (Guard*)oldMem;
// char* memAsChar = (char*)oldMem;
void* newMem;
if (oldMem == 0)
return unity_malloc(size);
if (oldMem == NULL) return unity_malloc(size);
guard--;
if (isOverrun(oldMem))
{
release_memory(oldMem);
TEST_FAIL_MESSAGE("Buffer overrun detected during realloc()");
UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during realloc()");
}
if (size == 0)
{
release_memory(oldMem);
return 0;
return NULL;
}
if (guard->size >= size)
return oldMem;
if (guard->size >= size) return oldMem;
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC /* Optimization if memory is expandable */
if (oldMem == unity_heap + heap_index - guard->size - sizeof(end) &&
heap_index + size - guard->size <= UNITY_INTERNAL_HEAP_SIZE_BYTES)
{
release_memory(oldMem); /* Not thread-safe, like unity_heap generally */
return unity_malloc(size); /* No memcpy since data is in place */
}
#endif
newMem = unity_malloc(size);
if (newMem == NULL) return NULL; /* Do not release old memory */
memcpy(newMem, oldMem, guard->size);
unity_free(oldMem);
release_memory(oldMem);
return newMem;
}
//--------------------------------------------------------
//Automatic pointer restoration functions
typedef struct _PointerPair
/*-------------------------------------------------------- */
/*Automatic pointer restoration functions */
struct PointerPair
{
struct _PointerPair * next;
void ** pointer;
void * old_value;
} PointerPair;
void** pointer;
void* old_value;
};
enum {MAX_POINTERS=50};
static PointerPair pointer_store[MAX_POINTERS+1];
static struct PointerPair pointer_store[UNITY_MAX_POINTERS];
static int pointer_index = 0;
void UnityPointer_Init(void)
......@@ -291,18 +319,18 @@ void UnityPointer_Init(void)
pointer_index = 0;
}
void UnityPointer_Set(void ** pointer, void * newValue)
void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line)
{
if (pointer_index >= MAX_POINTERS)
if (pointer_index >= UNITY_MAX_POINTERS)
{
TEST_FAIL_MESSAGE("Too many pointers set");
UNITY_TEST_FAIL(line, "Too many pointers set");
}
else
{
pointer_store[pointer_index].pointer = pointer;
pointer_store[pointer_index].old_value = *pointer;
*pointer = newValue;
pointer_index++;
pointer_store[pointer_index].pointer = pointer;
pointer_store[pointer_index].old_value = *pointer;
*pointer = newValue;
pointer_index++;
}
}
......@@ -312,26 +340,10 @@ void UnityPointer_UndoAllSets(void)
{
pointer_index--;
*(pointer_store[pointer_index].pointer) =
pointer_store[pointer_index].old_value;
pointer_store[pointer_index].old_value;
}
}
UNITY_COUNTER_TYPE UnityFailureCount(void)
{
return Unity.TestFailures;
}
UNITY_COUNTER_TYPE UnityIgnoreCount(void)
{
return Unity.TestIgnores;
}
UNITY_COUNTER_TYPE UnityTestsCount(void)
{
return Unity.NumberOfTests;
}
int UnityGetCommandLineOptions(int argc, const char* argv[])
{
int i;
......@@ -374,12 +386,20 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
{
if (*(argv[i]) >= '0' && *(argv[i]) <= '9')
{
UnityFixture.RepeatCount = (unsigned int)atoi(argv[i]);
unsigned int digit = 0;
UnityFixture.RepeatCount = 0;
while (argv[i][digit] >= '0' && argv[i][digit] <= '9')
{
UnityFixture.RepeatCount *= 10;
UnityFixture.RepeatCount += (unsigned int)argv[i][digit++] - '0';
}
i++;
}
}
} else {
// ignore unknown parameter
}
else
{
/* ignore unknown parameter */
i++;
}
}
......@@ -390,24 +410,21 @@ void UnityConcludeFixtureTest(void)
{
if (Unity.CurrentTestIgnored)
{
//if (UnityFixture.Verbose)
//{
UNITY_OUTPUT_CHAR('\n');
//}
Unity.TestIgnores++;
UNITY_PRINT_EOL();
}
else if (!Unity.CurrentTestFailed)
{
if (UnityFixture.Verbose)
{
UnityPrint(" PASS");
UNITY_OUTPUT_CHAR('\n');
UNITY_PRINT_EOL();
}
}
else if (Unity.CurrentTestFailed)
else /* Unity.CurrentTestFailed */
{
Unity.TestFailures++;
UNITY_OUTPUT_CHAR('\n');
UNITY_PRINT_EOL();
}
Unity.CurrentTestFailed = 0;
......
//- Copyright (c) 2010 James Grenning and Contributed to Unity Project
/* ==========================================
Unity Project - A Test Framework for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
SPDX-License-Identifier: MIT
========================================== */
/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
* ==========================================
* Unity Project - A Test Framework for C
* Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
* [Released under MIT License. Please refer to license.txt for details]
* ========================================== */
#ifndef UNITY_FIXTURE_H_
#define UNITY_FIXTURE_H_
......@@ -49,38 +49,35 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void));
}\
void TEST_##group##_##name##_(void)
#define DECLARE_TEST_CASE(group, name) \
void TEST_##group##_##name##_run(void)
/* Call this for each test, insider the group runner */
#define RUN_TEST_CASE(group, name) \
{ DECLARE_TEST_CASE(group, name);\
{ void TEST_##group##_##name##_run(void);\
TEST_##group##_##name##_run(); }
//This goes at the bottom of each test file or in a separate c file
/* This goes at the bottom of each test file or in a separate c file */
#define TEST_GROUP_RUNNER(group)\
void TEST_##group##_GROUP_RUNNER_runAll(void);\
void TEST_##group##_GROUP_RUNNER(void);\
void TEST_##group##_GROUP_RUNNER(void)\
{\
TEST_##group##_GROUP_RUNNER_runAll();\
}\
void TEST_##group##_GROUP_RUNNER_runAll(void)
void TEST_##group##_GROUP_RUNNER(void)
//Call this from main
/* Call this from main */
#define RUN_TEST_GROUP(group)\
{ void TEST_##group##_GROUP_RUNNER(void);\
TEST_##group##_GROUP_RUNNER(); }
//CppUTest Compatibility Macros
#define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&ptr, (void*)newPointerValue)
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR(expected, actual)
/* CppUTest Compatibility Macros */
#ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS
/* Sets a pointer and automatically restores it to its old value after teardown */
#define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__)
#define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual))
#define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual))
#define FAIL(message) TEST_FAIL_MESSAGE((message))
#define CHECK(condition) TEST_ASSERT_TRUE((condition))
#define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual))
#define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual))
#define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_FLOAT_WITHIN(((expected), (actual), (delta))
#define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual))
#endif
/* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */
void UnityMalloc_MakeMallocFailAfterCount(int count);
#endif /* UNITY_FIXTURE_H_ */
//- Copyright (c) 2010 James Grenning and Contributed to Unity Project
/* ==========================================
Unity Project - A Test Framework for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
SPDX-License-Identifier: MIT
========================================== */
/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
* ==========================================
* Unity Project - A Test Framework for C
* Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
* [Released under MIT License. Please refer to license.txt for details]
* ========================================== */
#ifndef UNITY_FIXTURE_INTERNALS_H_
#define UNITY_FIXTURE_INTERNALS_H_
typedef struct _UNITY_FIXTURE_T
#ifdef __cplusplus
extern "C"
{
#endif
struct UNITY_FIXTURE_T
{
int Verbose;
unsigned int RepeatCount;
const char* NameFilter;
const char* GroupFilter;
} UNITY_FIXTURE_T;
};
extern struct UNITY_FIXTURE_T UnityFixture;
typedef void unityfunction(void);
void UnityTestRunner(unityfunction * setup,
unityfunction * body,
unityfunction * teardown,
const char * printableName,
const char * group,
const char * name,
const char * file, int line);
void UnityIgnoreTest(const char * printableName, const char * group, const char * name);
void UnityTestRunner(unityfunction* setup,
unityfunction* body,
unityfunction* teardown,
const char* printableName,
const char* group,
const char* name,
const char* file, unsigned int line);
void UnityIgnoreTest(const char* printableName, const char* group, const char* name);
void UnityMalloc_StartTest(void);
void UnityMalloc_EndTest(void);
UNITY_COUNTER_TYPE UnityFailureCount(void);
UNITY_COUNTER_TYPE UnityIgnoreCount(void);
UNITY_COUNTER_TYPE UnityTestsCount(void);
int UnityGetCommandLineOptions(int argc, const char* argv[]);
void UnityConcludeFixtureTest(void);
void UnityPointer_Set(void ** ptr, void * newValue);
void UnityPointer_Set(void** ptr, void* newValue, UNITY_LINE_TYPE line);
void UnityPointer_UndoAllSets(void);
void UnityPointer_Init(void);
#ifndef UNITY_MAX_POINTERS
#define UNITY_MAX_POINTERS 5
#endif
void UnityAssertEqualPointer(const void * expected,
const void * actual,
const char* msg,
const UNITY_LINE_TYPE lineNumber);
#ifdef __cplusplus
}
#endif
#endif /* UNITY_FIXTURE_INTERNALS_H_ */
//- Copyright (c) 2010 James Grenning and Contributed to Unity Project
/* ==========================================
Unity Project - A Test Framework for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
SPDX-License-Identifier: MIT
========================================== */
/* Copyright (c) 2010 James Grenning and Contributed to Unity Project
* ==========================================
* Unity Project - A Test Framework for C
* Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
* [Released under MIT License. Please refer to license.txt for details]
* ========================================== */
#ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_
#define UNITY_FIXTURE_MALLOC_OVERRIDES_H_
#include <stddef.h>
// This function is used by the Unity Fixture to allocate memory on
// the heap and can be overridden with platform-specific heap
// implementations. For example, when using FreeRTOS
// UNITY_FIXTURE_MALLOC becomes pvPortMalloc().
#ifndef UNITY_FIXTURE_MALLOC
#define UNITY_FIXTURE_MALLOC( SIZE ) malloc( ( SIZE ) )
#else
extern void * UNITY_FIXTURE_MALLOC(size_t size);
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC
/* Define this macro to remove the use of stdlib.h, malloc, and free.
* Many embedded systems do not have a heap or malloc/free by default.
* This internal unity_malloc() provides allocated memory deterministically from
* the end of an array only, unity_free() only releases from end-of-array,
* blocks are not coalesced, and memory not freed in LIFO order is stranded. */
#ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES
#define UNITY_INTERNAL_HEAP_SIZE_BYTES 256
#endif
#endif
// This function is used by the Unity Fixture to release memory in the
// heap and can be overridden with platform-specific heap
// implementations. For example, when using FreeRTOS
// UNITY_FIXTURE_FREE becomes vPortFree().
#ifndef UNITY_FIXTURE_FREE
#define UNITY_FIXTURE_FREE( PTR ) free( ( PTR ) )
/* These functions are used by the Unity Fixture to allocate and release memory
* on the heap and can be overridden with platform-specific implementations.
* For example, when using FreeRTOS UNITY_FIXTURE_MALLOC becomes pvPortMalloc()
* and UNITY_FIXTURE_FREE becomes vPortFree(). */
#if !defined(UNITY_FIXTURE_MALLOC) || !defined(UNITY_FIXTURE_FREE)
#include <stdlib.h>
#define UNITY_FIXTURE_MALLOC(size) malloc(size)
#define UNITY_FIXTURE_FREE(ptr) free(ptr)
#else
extern void UNITY_FIXTURE_FREE(void *ptr);
extern void* UNITY_FIXTURE_MALLOC(size_t size);
extern void UNITY_FIXTURE_FREE(void* ptr);
#endif
#define malloc unity_malloc
......
This diff is collapsed.
......@@ -258,6 +258,9 @@ def cmd_configure(ctx, config):
('gnu99', '-std=gnu99'),
# this quiets most of macOS warnings on -fpie
('unused', '-Qunused-arguments'),
('w_format', '-Wformat'),
# fails on OpenBSD 6
('w_format_signedness', '-Wformat-signedness'),
]
# Check which linker flags are supported
......@@ -291,7 +294,6 @@ def cmd_configure(ctx, config):
"-Wcast-qual",
"-Wdisabled-optimization",
"-Wfloat-equal", # Not Ready For Prime Time
"-Wformat",
"-Wformat-nonliteral", # needs -Wformat
"-Wformat-security", # needs -Wformat
"-Wimplicit-function-declaration",
......@@ -311,8 +313,6 @@ def cmd_configure(ctx, config):
"-Wwrite-strings",
] + ctx.env.CFLAGS
cc_test_flags += [
# fails on OpenBSD 6
('w_format_signedness', '-Wformat-signedness'),
# fails on Solaris and OpenBSD 6
('w_sign_conversion', "-Wsign-conversion"),
# fails on clang
......@@ -383,6 +383,8 @@ int main(int argc, char **argv) {
# debug warnings that are not available with all compilers
if ctx.env.HAS_w_format_signedness:
ctx.env.CFLAGS = ['-Wformat-signedness'] + ctx.env.CFLAGS
if ctx.env.HAS_w_format:
ctx.env.CFLAGS = ['-Wformat'] + ctx.env.CFLAGS
if ctx.env.HAS_w_sign_conversion:
ctx.env.CFLAGS = ['-Wsign-conversion'] + ctx.env.CFLAGS
......