Ensure that the test version of the command line tool is stable for benchmarking (#2076)
Some benchmark suites contain test cases that have nonreproducible behaviour. This is mostly caused by relying on "now" when dealing with dates or timestamps, instead of using a fixed moment. (A notorious example is the crypto-aes.js test case of the sunspider bechmark suite, where the heap memory consumption can vary between 34K-41K heap because of using `(new Date()).getTime()`.) This commit renames the jerry-minimal command line tool to jerry-test (to better reflect its purpose) and adds extra code, which intercepts some calls to libc (`gettimeofday`, `rand`) and pins their results to some fixed values. This makes the tool useless in a general case but ensures stable results when benchmarking -- for which it is mostly used. As a side effect, the commit also changes jerry-libc by making all libc functions weak symbols to allow their override from application code. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source contains libc overrides for the sake of stable benchmarking. If
|
||||
* building a binary for the purpose of benchmarking, the object compiled from
|
||||
* this source is to be injected into the list of objects-to-be-linked before
|
||||
* the list of libraries-to-be-linked to ensure that the linker picks up these
|
||||
* implementations.
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
/*
|
||||
* Note:
|
||||
* This is nasty and dangerous. However, we only need the timeval structure
|
||||
* from sys/time.h. Unfortunately, the same header also declares
|
||||
* gettimeofday, which has different declarations on different platforms
|
||||
* (e.g., macOS, Linux). So, instead of #ifdef'ing for platforms, we simply
|
||||
* tweak the header to declare another function. Don't try this at home.
|
||||
*/
|
||||
#define gettimeofday __prevent_conflicting_gettimeofday_declarations__
|
||||
#include <sys/time.h>
|
||||
#undef gettimeofday
|
||||
|
||||
int gettimeofday (struct timeval *, void *);
|
||||
|
||||
/**
|
||||
* Useless but stable gettimeofday implementation. Returns Epoch. Ensures that
|
||||
* test cases relying on "now" yield stable results.
|
||||
*/
|
||||
int gettimeofday (struct timeval *tv,
|
||||
void *tz)
|
||||
{
|
||||
(void) tz;
|
||||
tv->tv_sec = 0;
|
||||
tv->tv_usec = 0;
|
||||
return 0;
|
||||
} /* gettimeofday */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
int rand (void);
|
||||
|
||||
/**
|
||||
* Useless but stable rand implementation. Returns 4. Ensures that test cases
|
||||
* relying on randomness yield stable results.
|
||||
*/
|
||||
int rand (void)
|
||||
{
|
||||
return 4; /* Chosen by fair dice roll. Guaranteed to be random. */
|
||||
} /* rand */
|
||||
Reference in New Issue
Block a user