Project
Loading...
Searching...
No Matches
testStaticTLSReserve.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test SimSetup StaticTLSReserve
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
17
19
20BOOST_AUTO_TEST_CASE(missing_or_broken_reserve_is_added)
21{
22 const std::string reserve = "glibc.rtld.optional_static_tls=32768";
23 BOOST_CHECK_EQUAL(withStaticTLSReserve(nullptr, 32768), reserve);
24 BOOST_CHECK_EQUAL(withStaticTLSReserve("", 32768), reserve);
25 // the value as it arrives in GRID jobs
26 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls", 32768), reserve);
27 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=", 32768), reserve);
28 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=512", 32768), reserve);
29 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=-1", 32768), reserve);
30 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=32768x", 32768), reserve);
31}
32
33BOOST_AUTO_TEST_CASE(sufficient_reserve_is_kept)
34{
35 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=32768", 32768), "");
36 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=1048576", 32768), "");
37 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.malloc.arena_max=4:glibc.rtld.optional_static_tls=65536", 32768), "");
38 // glibc also takes hex and octal
39 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=0x100000", 32768), "");
40 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=0100000", 32768), "");
41 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=0x200", 32768), "glibc.rtld.optional_static_tls=32768");
42}
43
44BOOST_AUTO_TEST_CASE(malformed_entries_are_dropped)
45{
46 // glibc ignores the whole string if one entry has no value, so a good reserve next to it does not count
47 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=32768:glibc.malloc.arena_max", 32768),
48 "glibc.rtld.optional_static_tls=32768");
49 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.malloc.arena_max:glibc.malloc.tcache_count=0", 32768),
50 "glibc.rtld.optional_static_tls=32768:glibc.malloc.tcache_count=0");
51}
52
53BOOST_AUTO_TEST_CASE(other_tunables_are_kept)
54{
55 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.malloc.arena_max=4", 32768),
56 "glibc.rtld.optional_static_tls=32768:glibc.malloc.arena_max=4");
57 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls:glibc.malloc.arena_max=4", 32768),
58 "glibc.rtld.optional_static_tls=32768:glibc.malloc.arena_max=4");
59 // a longer name is a different tunable
60 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tlsx=1", 32768),
61 "glibc.rtld.optional_static_tls=32768:glibc.rtld.optional_static_tlsx=1");
62}
63
64BOOST_AUTO_TEST_CASE(last_reserve_counts)
65{
66 // glibc applies the entries in order, so a later small reserve wins over an earlier large one
67 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=65536:glibc.rtld.optional_static_tls=512", 32768),
68 "glibc.rtld.optional_static_tls=32768");
69 BOOST_CHECK_EQUAL(withStaticTLSReserve("glibc.rtld.optional_static_tls=512:glibc.rtld.optional_static_tls=65536", 32768), "");
70}
std::string withStaticTLSReserve(const char *tunables, unsigned long reserve=Geant4StaticTLSReserve)
BOOST_AUTO_TEST_CASE(missing_or_broken_reserve_is_added)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())