Commit Graph

51 Commits

Author SHA1 Message Date
Edward Thomson
abedcfe71c tests: reset the allocator to the default
Instead of setting the allocator to stdalloc, just pass `NULL`, in case
we're running with the debug allocator.
2024-05-13 11:30:25 +01:00
Edward Thomson
49487b5e39 clar: canonicalize temp sandbox directory everywhere
We currently only canonicalize the temp sandbox directory on macOS,
which is critical since `/tmp` is really `/private/tmp`. However, we
should do it everywhere, so that tests can actually expect a consistent
outcome by looking at `clar_sandbox_path()`.
2024-02-19 16:40:22 +00:00
Edward Thomson
fddfca3526 tests: add cl_assert_equal_oidstr helper method 2024-01-15 00:15:10 +00:00
Peter Pettersson
6847eed97a tests: remove test for strcasecmp
strcasecmp is a posix function, testing it doesn't make sense.
Functions that needs unsigned compare should use git__strcasecmp()
2023-12-17 13:48:12 +01:00
Edward Thomson
839b249525 tests: update to latest clar 2023-12-14 14:26:09 +00:00
Edward Thomson
2757641620 tests: only copy when ptr is non-NULL
Avoid passing a `NULL` ptr to `memcpy` -- that's UB (even if size is 0)
2023-05-15 11:04:37 +01:00
Patrick Steinhardt
90cc07711c tests: add allocator with limited number of bytes
In several circumstances, we get bug reports about things that happen in
situations where the environment is quite limited with regards to
available memory. While it's expected that functionality will fail if
memory allocations fail, the assumption is that we should do so in a
controlled way. Most importantly, we do not want to crash hard due to
e.g. accessing NULL pointers.

Naturally, it is quite hard to debug such situations. But since our
addition of pluggable allocators, we are able to implement allocators
that fail in deterministic ways, e.g. after a certain amount of bytes
has been allocated. This commit does exactly that.

To be able to properly keep track of the amount of bytes currently
allocated, allocated pointers contain tracking information. This
tracking information is currently limited to the number of bytes
allocated, so that we can correctly replenish them on calling `free` on
the pointer. In the future, it would be feasible to extend the tracked
information even further, e.g. by adding information about file and line
where the allocation has been performed. As this introduced some
overhead to allocations though, only information essential to limited
allocations is currently tracked.
2023-05-15 09:28:47 +01:00
Edward Thomson
6c0d5b11c0 util: make monotonic time fn return ms
`git__timer` is now `git_time_monotonic`, and returns milliseconds
since an arbitrary epoch.

Using a floating point to store the number of seconds elapsed was
clever, as it better supports the wide range of precision from the
different monotonic clocks of different systems. But we're a version
control system, not a real-time clock.

Milliseconds is a good enough precision for our work _and_ it's the
units that system calls like `poll` take and that our users interact
with.

Make `git_time_monotonic` return the monotonically increasing number
of milliseconds "ticked" since some arbitrary epoch.
2023-05-13 16:42:04 +01:00
Edward Thomson
0d7f3f5291 utf8: add conversion with size and refactor names
Add functions to use convert a string with length, instead of assuming
NUL termination.

In addition, move the utf8 to 16 conversion routines into the `git_utf8`
namespace instead of using namespaceless `git__` prefixed names.
2023-03-21 09:14:06 +00:00
Edward Thomson
80742e159c Merge pull request #6456 from libgit2/ethomson/sha256_experimental
SHA256: more SHA256 support
2023-02-14 17:01:23 +00:00
Edward Thomson
f6dbf9c594 tests: helpers for getting ints from configuration 2023-02-12 21:26:11 +00:00
Edward Thomson
ff67b5e117 tests: use a dummy homedir
Use a dummy home directory for tests to avoid user data leaking into
test execution.
2023-02-09 12:10:40 +00:00
Edward Thomson
f32ec999b0 tests: configure temporary homedirs correctly
Now that we've split the notion of the home directory from the global
configuration store, our tests should use the appropriate one based on
what they're doing.
2023-02-09 12:10:40 +00:00
Edward Thomson
ed26a908fe clar: cross-platform elapsed time counter
Abstract time counter for tests; use gettimeofday on Unix and
GetTickCount on Windows.
2023-01-25 09:37:22 +00:00
Edward Thomson
4e15c9c87f tests: fix clar declarations 2023-01-25 09:36:48 +00:00
Edward Thomson
6bf0459a42 tests: update clar test runner
Update to the latest main version of clar, which includes improved xml
summary output.
2023-01-25 09:36:07 +00:00
Edward Thomson
6c57bac6b1 sha256: make sha256 an experimental optional feature
libgit2 can be built with optional, experimental sha256 support. This
allows consumers to begin testing and providing feedback for our sha256
support while we continue to develop it, and allows us to make API
breaking changes while we iterate on a final sha256 implementation.

The results will be `git2-experimental.dll` and installed as
`git2-experimental.h` to avoid confusion with a production libgit2.
2022-06-20 17:12:49 -04:00
Edward Thomson
817324134c clar: format sha256 in cl_assert_equal_oid 2022-06-20 17:05:29 -04:00
Edward Thomson
4161ebdd50 repo: make ownership checks optional
Introduce the `GIT_OPT_SET_OWNER_VALIDATION` option, so that users can
disable repository ownership validation.
2022-04-11 22:17:52 -04:00
Edward Thomson
25bc84fb8f refactor: move clar into separate directory 2022-02-22 22:07:45 -05:00
Edward Thomson
3344fddc97 refactor: tests is now tests/libgit2
Like we want to separate libgit2 and utility source code, we want to
separate libgit2 and utility tests.  Start by moving all the tests into
libgit2.
2022-02-22 22:07:45 -05:00
Edward Thomson
3f024b6d54 clar: declare summary functions as static 2021-11-11 17:21:32 -05:00
Edward Thomson
5368be3053 clar: support long paths on Windows 2021-05-05 23:11:52 +01:00
lhchavez
212ae9a70e Fix the -DENABLE_WERROR=ON build for gcc 10.2
This change makes it possible to build with newer versions of gcc
without warnings. There were two warnings issued:

* gcc 8 added
  [`-Wstringop-truncation`](https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/),
  which warns if a call to `strncpy(3)` is prone to accidentally
  truncating the destination string, since `strncpy(3)` does NOT add a
  terminating `NULL` if the destination buffer is not large enough to
  hold the input.

  This change uses the pattern suggested in
  https://us-cert.cisa.gov/bsi/articles/knowledge/coding-practices/strncpy-and-strncat
  to fix the locations flagged by gcc.
* There was a potentially uninitialized access of `dest` in `fs_copy`.
2020-12-21 07:02:54 -08:00
Philipp
6887e9dbf4 Removed FreeBSD-related macros. 2020-09-14 15:54:00 +02:00
Philipp
e937a2aa65 Fixed includes for FreeBSD. 2020-09-09 19:08:20 +02:00
Edward Thomson
cad7a1bad4 clar: include the function name 2020-06-05 08:49:07 +01:00
Edward Thomson
f7250cc36a clar: add tap output 2020-06-04 07:58:23 +01:00
Edward Thomson
691315e6e5 clar: add an output abstraction layer
Add an output abstraction layer, with a single output format, "clap",
the clar protocol, which is the current output format for clar.
2020-06-03 15:47:42 +01:00
Edward Thomson
107bf1f4be clar: print indirection 2020-06-03 11:47:13 +01:00
Edward Thomson
2a2c5b4027 clar: remove unused shell_out function 2020-06-02 09:03:48 +01:00
Edward Thomson
ee9e916308 clar: remove files internally instead of /bin/rm
Similar to how clar has used `/bin/cp` to copy files, it's used
`/bin/rm` to remove them.  This has similar deficiencies; meaning that
leaks is noisy and it's slow.  Move it to an internal function.
2020-06-02 09:03:48 +01:00
Edward Thomson
d03fd331f5 clar: copy files with sendfile on linux 2020-06-02 09:03:48 +01:00
Edward Thomson
8df4f51956 clar: copy files internally instead of /bin/cp
clar has historically shelled out to `/bin/cp` to copy test fixtures
into a sandbox.  This has two deficiencies:

1. It's slower than simply opening the source and destination and
   copying them in a read/write loop.  On my Mac, the `/bin/cp` based
   approach takes ~2:40 for a full test pass.  Using a read/write loop
   to copy the files ourselves takes ~1:50.

2. It's noisy.  Since the leak detector follows fork/exec, we'll end up
   running the leak detector on `/bin/cp`.  This would be fine, except
   that the leak detector spams the console on startup and shutdown, so
   it adds a _lot_ of additional information to the test runs that is
   useless.  By not forking and using this internal system, we see much
   less output.
2020-06-02 09:03:48 +01:00
Patrick Steinhardt
77d7e5eb94 clar: use size_t to keep track of current line number
We use the `__LINE__` macro in several places throughout clar to allow
easier traceability when e.g. a test fails. While `__LINE__` is of type
`size_t`, the clar functions all accept an integer and thus may loose
precision. While unlikely that any file in our codebase will exceed a
linecount of `INT_MAX`, let's convert it anyway to silence any compiler
warnings.
2019-07-05 11:31:52 +02:00
Edward Thomson
e595eeb5ab ci: use more compatible strftime formats
Windows lacks %F and %T formats for strftime.  Expand them to the
year/month/day and hour/minute/second formats, respectively.
2018-09-06 11:18:59 +01:00
Edward Thomson
b67a93ff81 clar: remove globals; error-check fprintf/fclose
Remove the global summary filename and file pointer; pass them in to the
summary functions as needed.  Error check the results of buffered I/O
calls.
2018-09-06 11:18:59 +01:00
Edward Thomson
baa5c20d08 clar: accept a value for the summary filename
Accept an (optional) value for the summary filename.  Continues to
default to summary.xml.
2018-09-06 11:17:01 +01:00
Edward Thomson
dbebcb04b4 clar: don't use a variable named time 2018-09-06 11:17:01 +01:00
Etienne Samson
59f1e477f7 Barebones JUnit XML output 2018-09-06 11:17:01 +01:00
Etienne Samson
bf9fc12670 Isolate test reports
This makes it possible to keep track of every test status (even
successful ones), and their errors, if any.
2018-09-06 11:17:01 +01:00
Nika Layzell
939d8d579d mailmap: Support path fixtures in cl_git_repository_init() 2018-06-14 22:43:27 -07:00
Matt Keeler
45a3b9cd6e tests: fix issue with /tmp paths on macOS[1] 2018-04-25 08:28:23 -07:00
Christine Poerschke
19f37f97bb add test status codes legend to the 'Started' test trace
motivation: (for someone new to the tests) it's puzzling to find the odd 'S' interspersed in the test output

proposed alternative test output (extract):

$ cmake --build . && ./libgit2_clar -srepo -v
...
Loaded 340 suites:
Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')

repo::config...
repo::discover..........
repo::env.
repo::getters...
repo::hashfile..
repo::head......................
repo::headtree....
repo::init.........................S
repo::message..
repo::new..
repo::open.............
repo::pathspec..........
repo::reservedname.....
repo::setters.....
repo::shallow....
repo::state.............
2017-11-13 13:16:28 +00:00
Edward Thomson
eadf37151b clar: test chdir 2015-06-29 22:13:40 +00:00
Edward Thomson
71686ddca6 clar: support hierarchical test resource data
Support hierarchical test resource data, such that you can have
`tests/resources/foo/bar` and move the `bar` directory in as
a fixture.

Calling `cl_fixture_sandbox` on a path that is not directly beneath
the test resources directory succeeds, placing that directory into
the test fixture.  (For example, `cl_fixture_sandbox("foo/bar")`
will sandbox the `foo/bar` directory as `bar`).

Add support for cleaning up directories created this way, by only
cleaning up the basename (in this example, `bar`) from the fixture
directory.
2015-06-22 12:00:15 -04:00
Edward Thomson
29eed1c74d clar: use a custom temp directory name 2014-10-24 10:50:57 -04:00
Vicent Marti
0f65733b08 Clar: skip tests 2014-04-02 18:50:47 +02:00
Edward Thomson
10be94e9dc Update clar to 587f88a 2014-03-28 10:39:07 -07:00
Russell Belfer
7be88b4c4d Update to latest clar 2014-01-31 13:44:09 -08:00