Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions iocore/aio/test_AIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "InkAPIInternal.h"
#include "tscore/I_Layout.h"
#include "tscore/TSSystemState.h"
#include "tscore/Random.h"
#include <iostream>
#include <fstream>

Expand Down Expand Up @@ -282,7 +283,7 @@ AIO_Device::do_fd(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
io->action = this;
io->thread = mutex->thread_holding;

switch (select_mode(drand48())) {
switch (select_mode(ts::Random::drandom())) {
case READ_MODE:
io->aiocb.aio_offset = seq_read_point;
io->aiocb.aio_nbytes = seq_read_size;
Expand Down Expand Up @@ -311,8 +312,8 @@ AIO_Device::do_fd(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
case RANDOM_READ_MODE: {
// fprintf(stderr, "random read started \n");
double p, f;
p = drand48();
f = drand48();
p = ts::Random::drandom();
f = ts::Random::drandom();
off_t o = 0;
if (f < hotset_frequency) {
o = static_cast<off_t>(p) * max_hotset_offset;
Expand Down Expand Up @@ -430,7 +431,7 @@ main(int /* argc ATS_UNUSED */, char *argv[])

RecProcessStart();
ink_aio_init(AIO_MODULE_PUBLIC_VERSION);
srand48(time(nullptr));
ts::Random::seed(time(nullptr));
printf("input file %s\n", argv[1]);
if (!read_config(argv[1])) {
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions iocore/cache/CacheDir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "tscore/hugepages.h"
#include "tscore/Regression.h"
#include "tscore/Random.h"

// #define LOOP_CHECK_MODE 1
#ifdef LOOP_CHECK_MODE
Expand Down Expand Up @@ -1400,8 +1401,7 @@ regress_rand_CacheKey(const CacheKey *key)
void
dir_corrupt_bucket(Dir *b, int s, Vol *d)
{
// coverity[dont_call]
int l = (static_cast<int>(dir_bucket_length(b, s, d) * drand48()));
int l = (static_cast<int>(dir_bucket_length(b, s, d) * ts::Random::drandom()));
Dir *e = b;
Dir *seg = d->dir_segment(s);
for (int i = 0; i < l; i++) {
Expand Down
6 changes: 3 additions & 3 deletions iocore/cache/CacheTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "P_Cache.h"
#include "P_CacheTest.h"
#include "tscore/Random.h"
#include <vector>
#include <cmath>
#include <cstdlib>
Expand Down Expand Up @@ -590,11 +591,10 @@ test_RamCache(RegressionTest *t, RamCache *cache, const char *name, int64_t cach

int sample_size = cache_size >> 6;
build_zipf();
srand48(13);
ts::Random::seed(13);
int *r = static_cast<int *>(ats_malloc(sample_size * sizeof(int)));
for (int i = 0; i < sample_size; i++) {
// coverity[dont_call]
r[i] = get_zipf(drand48());
r[i] = get_zipf(ts::Random::drandom());
}
data.clear();
int misses = 0;
Expand Down
4 changes: 2 additions & 2 deletions plugins/cache_promote/policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
limitations under the License.
*/
#include "tscore/BufferWriter.h"
#include "tscore/Random.h"
#include "policy.h"

bool
PromotionPolicy::doSample() const
{
if (_sample > 0) {
// coverity[dont_call]
double r = drand48();
double r = ts::Random::drandom();

if (_sample > r) {
TSDebug(PLUGIN_NAME, "checking sampling, is %f > %f? Yes!", _sample, r);
Expand Down
4 changes: 2 additions & 2 deletions proxy/hdrs/unit_tests/test_Hdrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "tscore/Regex.h"
#include "tscore/ink_time.h"
#include "tscore/Random.h"

#include "catch.hpp"

Expand Down Expand Up @@ -616,8 +617,7 @@ TEST_CASE("HdrTest", "[proxy][hdrtest]")

// (2) test a few times per day from 1/1/1970 to past 2010

// coverity[dont_call]
for (t = 0; t < 40 * 366 * (24 * 60 * 60); t += static_cast<int>(drand48() * (24 * 60 * 60))) {
for (t = 0; t < 40 * 366 * (24 * 60 * 60); t += static_cast<int>(ts::Random::drandom() * (24 * 60 * 60))) {
cftime_replacement(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", &t);
t2 = mime_parse_date(buffer, buffer + static_cast<int>(strlen(buffer)));
if (t2 != t) {
Expand Down
5 changes: 3 additions & 2 deletions src/tscore/unit_tests/test_MMH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "tscore/MMH.h"
#include "tscore/ink_memory.h"
#include "tscore/Random.h"
#include <catch.hpp>

#define TEST_COLLISIONS 10000000
Expand Down Expand Up @@ -71,10 +72,10 @@ TEST_CASE("MMH", "[libts][MMH]")
ink_code_MMH((unsigned char *)sc4, strlen(sc4), h.hash);
printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]);

srand48(time(nullptr));
ts::Random::seed(time(nullptr));
for (int xx = 0; xx < TEST_COLLISIONS; xx++) {
char xs[256];
xf[xx] = drand48();
xf[xx] = ts::Random::drandom();
sprintf(xs, "http://@npdev/%16.14f/4000;?", xf[xx]);
ink_code_MMH((unsigned char *)xs, strlen(xs), (unsigned char *)&xxh[xx]);
}
Expand Down
96 changes: 34 additions & 62 deletions tools/jtest/jtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "tscore/ink_args.h"
#include "tscore/I_Version.h"
#include "tscpp/util/TextView.h"
#include "tscore/Random.h"

/*
FTP - Traffic Server Template
Expand Down Expand Up @@ -1040,8 +1041,7 @@ process_header(int sock, char *buffer, int offset)
fd[sock].post_cl = atoi(post_cl + strlen("Content-Length: "));
ink_assert(post_cl && post_request && fd[sock].post_cl);
}
// coverity[dont_call]
if (drand48() > ims_rate) {
if (ts::Random::drandom() > ims_rate) {
ims = nullptr;
}
if (range) {
Expand Down Expand Up @@ -1146,10 +1146,8 @@ parse_header(int sock, int err)
} else {
fd[sock].keepalive--;
}
// coverity[dont_call]
if (fd[sock].length && drand48() < server_abort_rate) {
// coverity[dont_call]
fd[sock].length = (int)(drand48() * (fd[sock].length - 1));
if (fd[sock].length && ts::Random::drandom() < server_abort_rate) {
fd[sock].length = (int)(ts::Random::drandom() * (fd[sock].length - 1));
fd[sock].keepalive = 0;
}
poll_set(sock, nullptr, send_response);
Expand All @@ -1166,10 +1164,8 @@ parse_header(int sock, int err)
} else {
fd[sock].keepalive--;
}
// coverity[dont_call]
if (fd[sock].length && drand48() < server_abort_rate) {
// coverity[dont_call]
fd[sock].length = (int)(drand48() * (fd[sock].length - 1));
if (fd[sock].length && ts::Random::drandom() < server_abort_rate) {
fd[sock].length = (int)(ts::Random::drandom() * (fd[sock].length - 1));
fd[sock].keepalive = 0;
}
poll_set(sock, nullptr, send_response);
Expand Down Expand Up @@ -1462,8 +1458,7 @@ read_ftp_request(int sock)
} else if (STREQ(buffer, "MDTM")) {
double err_rand = 1.0;
if (ftp_mdtm_err_rate != 0.0) {
// coverity[dont_call]
err_rand = drand48();
err_rand = ts::Random::drandom();
}
if (err_rand < ftp_mdtm_err_rate) {
fd[sock].length = sprintf(fd[sock].req_header, "550 mdtm file not found\r\n");
Expand Down Expand Up @@ -1843,10 +1838,8 @@ gen_bfc_dist(double f = 10.0)
double rand2 = 0.0;
bool f_given = f < 9.0;
if (!f_given) {
// coverity[dont_call]
rand = drand48();
// coverity[dont_call]
rand2 = drand48();
rand = ts::Random::drandom();
rand2 = ts::Random::drandom();
} else {
rand = f;
rand2 = (f * 13.0) - floor(f * 13.0);
Expand Down Expand Up @@ -1897,8 +1890,7 @@ gen_bfc_dist(double f = 10.0)
// vary about the mean doc size for
// that class/size
if (!f_given) {
// coverity[dont_call]
size += (int)((-increment * 0.5) + (increment * drand48()));
size += (int)((-increment * 0.5) + (increment * ts::Random::drandom()));
}
if (verbose) {
printf("gen_bfc_dist %d\n", size);
Expand Down Expand Up @@ -2452,11 +2444,9 @@ read_response(int sock)
fd[sock].length -= lbody;
ink_assert(fd[sock].length >= 0);
fd[sock].req_pos = -1;
// coverity[dont_call]
if (fd[sock].length && drand48() < client_abort_rate) {
fd[sock].client_abort = 1;
// coverity[dont_call]
fd[sock].length = (int)(drand48() * (fd[sock].length - 1));
if (fd[sock].length && ts::Random::drandom() < client_abort_rate) {
fd[sock].client_abort = 1;
fd[sock].length = (int)(ts::Random::drandom() * (fd[sock].length - 1));
fd[sock].keepalive = 0;
fd[sock].drop_after_CL = 1;
}
Expand Down Expand Up @@ -2881,10 +2871,8 @@ make_range_header(int sock, double dr, char *rbuf, int size_limit)
return;

tmp[0] = gen_bfc_dist(dr - 1.0);
// coverity[dont_call]
tmp[1] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1);
// coverity[dont_call]
tmp[2] = ((int)(drand48() * 1000000)) % (tmp[0] - 1 - 0 + 1) + tmp[1] + 100;
tmp[1] = ((int)(ts::Random::drandom() * 1000000)) % (tmp[0] - 1 - 0 + 1);
tmp[2] = ((int)(ts::Random::drandom() * 1000000)) % (tmp[0] - 1 - 0 + 1) + tmp[1] + 100;

if (tmp[0] > 100) {
if (tmp[0] <= tmp[2]) {
Expand All @@ -2910,10 +2898,8 @@ make_range_header(int sock, double dr, char *rbuf, int size_limit)
static void
make_random_url(int sock, double *dr, double *h)
{
// coverity[dont_call]
*dr = drand48();
// coverity[dont_call]
*h = drand48();
*dr = ts::Random::drandom();
*h = ts::Random::drandom();

if (zipf == 0.0) {
if (*h < hitrate) {
Expand Down Expand Up @@ -2954,8 +2940,7 @@ make_nohost_request(int sock, double dr, const char *evo_str, const char *extens
"\r\n",
local_host, server_port, dr, fd[sock].response_length, evo_str, extension,
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "Connection: close\r\n",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
} else {
sprintf(fd[sock].req_header,
ftp ? "GET ftp://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
Expand All @@ -2972,8 +2957,7 @@ make_nohost_request(int sock, double dr, const char *evo_str, const char *extens
"\r\n",
local_host, server_port, dr, fd[sock].response_length, evo_str, extension,
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
}
break;
case 1:
Expand All @@ -2990,8 +2974,7 @@ make_nohost_request(int sock, double dr, const char *evo_str, const char *extens
"\r\n",
local_host, server_port, dr, fd[sock].response_length, evo_str, extension, fd[sock].response_length,
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "Connection: close\r\n",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
} else {
sprintf(fd[sock].req_header,
"POST http://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
Expand All @@ -3003,8 +2986,7 @@ make_nohost_request(int sock, double dr, const char *evo_str, const char *extens
"\r\n",
local_host, server_port, dr, fd[sock].response_length, evo_str, extension, fd[sock].response_length,
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
}
post_length = fd[sock].response_length;
break;
Expand All @@ -3025,8 +3007,7 @@ make_nohost_request(int sock, double dr, const char *evo_str, const char *extens
"\r\n",
local_host, server_port, dr, fd[sock].response_length, evo_str, extension, post_size,
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "Connection: close\r\n",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, "Host: localhost\r\n", rbuf, cookie);
} else {
sprintf(fd[sock].req_header,
"POST http://%s:%d/%12.10f/%d%s%s HTTP/1.0\r\n"
Expand All @@ -3038,8 +3019,7 @@ make_nohost_request(int sock, double dr, const char *evo_str, const char *extens
"\r\n",
local_host, server_port, dr, fd[sock].response_length, evo_str, extension, post_size,
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
}
post_length = post_size;
break;
Expand All @@ -3060,9 +3040,8 @@ make_host1_request(int sock, double dr, const char *evo_str, const char *extensi
"%s"
"\r\n",
dr, fd[sock].response_length, evo_str, extension, local_host, server_port,
fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "", reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "",
eheaders, cookie);
return 0;
}

Expand All @@ -3078,8 +3057,7 @@ make_host2_request(int sock, double dr, const char *evo_str, const char *extensi
"%s"
"\r\n",
dr, fd[sock].response_length, evo_str, extension, fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "", eheaders, cookie);
return 0;
}

Expand Down Expand Up @@ -3116,9 +3094,8 @@ build_request(int sock)
}
}
char cookie[256];
*cookie = 0;
// coverity[dont_call]
fd[sock].nalternate = (int)(alternates * drand48());
*cookie = 0;
fd[sock].nalternate = (int)(alternates * ts::Random::drandom());
if (alternates) {
if (!vary_user_agent) {
sprintf(cookie, "Cookie: jtest-cookie-%d\r\n", fd[sock].nalternate);
Expand Down Expand Up @@ -3577,10 +3554,8 @@ make_url_client(const char *url, const char *base_url, bool seen, bool unthrottl
"Accept: */*\r\n"
"%s"
"\r\n",
curl,
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "",
eheaders);
curl, reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "",
fd[sock].keepalive ? "Proxy-Connection: Keep-Alive\r\n" : "", eheaders);
} else {
sprintf(fd[sock].req_header,
"GET /%s%s%s%s%s HTTP/1.0\r\n"
Expand All @@ -3591,9 +3566,8 @@ make_url_client(const char *url, const char *base_url, bool seen, bool unthrottl
"%s"
"\r\n",
path, xquer ? "?" : "", quer, xpar ? ";" : "", para, host,
// coverity[dont_call]
reload_rate > drand48() ? "Pragma: no-cache\r\n" : "", fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "",
eheaders);
reload_rate > ts::Random::drandom() ? "Pragma: no-cache\r\n" : "",
fd[sock].keepalive ? "Connection: Keep-Alive\r\n" : "", eheaders);
}

if (verbose) {
Expand Down Expand Up @@ -3659,11 +3633,9 @@ main(int argc __attribute__((unused)), const char *argv[])
process_args(&appVersionInfo, argument_descriptions, n_argument_descriptions, argv);

if (!drand_seed) {
// coverity[dont_call]
srand48((long)time(nullptr));
ts::Random::seed((long)time(nullptr));
} else {
// coverity[dont_call]
srand48((long)drand_seed);
ts::Random::seed((long)drand_seed);
}
if (zipf != 0.0) {
build_zipf();
Expand Down