-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
112 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +0,0 @@ | ||
load( | ||
"@libc_replacer//:cc.bzl", | ||
"cc_libc_replacer_binary", | ||
"cc_libc_replacer_test", | ||
) | ||
|
||
cc_libc_replacer_binary( | ||
name = "time_test_binary", | ||
testonly = True, | ||
srcs = ["time_test.cpp"], | ||
deps = ["@googletest//:gtest_main"], | ||
) | ||
|
||
cc_libc_replacer_test( | ||
name = "time_test", | ||
timeout = "short", | ||
srcs = ["time_test.cpp"], | ||
deps = ["@googletest//:gtest_main"], | ||
) | ||
|
||
sh_test( | ||
name = "binary_test", | ||
timeout = "short", | ||
srcs = [":time_test_binary"], | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load( | ||
"@libc_replacer//:cc.bzl", | ||
"cc_libc_replacer_binary", | ||
"cc_libc_replacer_test", | ||
) | ||
|
||
cc_libc_replacer_binary( | ||
name = "test_binary", | ||
testonly = True, | ||
srcs = ["test.c"], | ||
) | ||
|
||
cc_libc_replacer_test( | ||
name = "test", | ||
timeout = "short", | ||
srcs = ["test.c"], | ||
) | ||
|
||
sh_test( | ||
name = "binary_test", | ||
timeout = "short", | ||
srcs = [":test_binary"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <libc_replacer/cc/interface.h> | ||
|
||
#include <assert.h> | ||
#include <time.h> | ||
|
||
static clock_t mock_clock(void) { return 123.0; } | ||
|
||
int main(void) { | ||
libc_replacer_overwrite_clock(mock_clock); | ||
const clock_t got = clock(); | ||
libc_replacer_reset_clock(); | ||
assert(got == 123.0); | ||
const clock_t got_after_reset = clock(); | ||
assert(got_after_reset != 123.0); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load( | ||
"@libc_replacer//:cc.bzl", | ||
"cc_libc_replacer_binary", | ||
"cc_libc_replacer_test", | ||
) | ||
|
||
cc_libc_replacer_binary( | ||
name = "test_binary", | ||
testonly = True, | ||
srcs = ["test.c"], | ||
) | ||
|
||
cc_libc_replacer_test( | ||
name = "test", | ||
timeout = "short", | ||
srcs = ["test.c"], | ||
) | ||
|
||
sh_test( | ||
name = "binary_test", | ||
timeout = "short", | ||
srcs = [":test_binary"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <libc_replacer/cc/interface.h> | ||
|
||
#include <assert.h> | ||
#include <time.h> | ||
|
||
static time_t mock_time(time_t *tloc) { | ||
(void)tloc; | ||
return 123; | ||
} | ||
|
||
int main(void) { | ||
libc_replacer_overwrite_time(mock_time); | ||
const time_t got = time(NULL); | ||
libc_replacer_reset_time(); | ||
assert(got == 123); | ||
const time_t got_after_reset = time(NULL); | ||
assert(got_after_reset != 123); | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""C/C++ implementations to replace `clock`. | ||
""" | ||
|
||
cc_library( | ||
name = "clock", | ||
srcs = ["clock.c"], | ||
hdrs = ["clock.h"], | ||
linkopts = ["-Wl,-wrap=clock"], | ||
visibility = ["//libc_replacer/cc:__pkg__"], | ||
deps = ["//libc_replacer/cc/internal"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "libc_replacer/cc/clock/clock.h" // IWYU pragma: associated | ||
#include "libc_replacer/cc/internal/definition_helper.h" | ||
|
||
#include <time.h> | ||
|
||
LIBC_REPLACER_INTERNAL_DEFINE(clock, clock_t, (void, )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef INCLUDE_GUARD_LIBC_REPLACER_CC_TIME_CLOCK_H_ | ||
#define INCLUDE_GUARD_LIBC_REPLACER_CC_TIME_CLOCK_H_ | ||
|
||
#include "libc_replacer/cc/internal/declaration_helper.h" | ||
|
||
#include <time.h> | ||
|
||
LIBC_REPLACER_INTERNAL_DECLARE(clock, clock_t, (void, )) | ||
|
||
#endif // INCLUDE_GUARD_LIBC_REPLACER_CC_TIME_CLOCK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters