From: Anders Björklund Date: Mon, 30 Jun 2014 17:50:49 +0000 (+0200) Subject: Make the cleanup limit into a configurable variable X-Git-Tag: v3.3~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8ca6ad32c338cf145826e8091c5e3aeeb7f538a;p=thirdparty%2Fccache.git Make the cleanup limit into a configurable variable When doing manual cleanups, it is useful to be able to set the cleanup limit multiple rather than hardcoding it as 80% always. --- diff --git a/MANUAL.txt b/MANUAL.txt index 5020e65e3..47a5e9294 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -397,6 +397,11 @@ WRAPPERS>>. If true, ccache will not discard the comments before hashing preprocessor output. This can be used to check documentation with *-Wdocumentation*. +*limit_multiple* (*CCACHE_LIMIT_MULTIPLE*):: + + Sets the limit when cleaning up. Files are deleted (in LRU order) + until the levels are below the limit. The default is 0.8 (= 80%). + *log_file* (*CCACHE_LOGFILE*):: If set to a file path, ccache will write information on what it is doing to diff --git a/ccache.c b/ccache.c index f60adb6c7..aa749a3a8 100644 --- a/ccache.c +++ b/ccache.c @@ -3143,6 +3143,9 @@ ccache(int argc, char *argv[]) conf->direct_mode = false; } + if (conf->limit_multiple < 0.0) conf->limit_multiple = 0.0; + if (conf->limit_multiple > 1.0) conf->limit_multiple = 1.0; + // Arguments (except -E) to send to the preprocessor. struct args *preprocessor_args; // Arguments to send to the real compiler. diff --git a/cleanup.c b/cleanup.c index 4ee48d5aa..db37bb1bc 100644 --- a/cleanup.c +++ b/cleanup.c @@ -17,11 +17,6 @@ #include "ccache.h" -// When "max files" or "max cache size" is reached, one of the 16 cache -// subdirectories is cleaned up. When doing so, files are deleted (in LRU -// order) until the levels are below LIMIT_MULTIPLE. -#define LIMIT_MULTIPLE 0.8 - static struct files { char *fname; time_t mtime; @@ -179,8 +174,13 @@ cleanup_dir(struct conf *conf, const char *dir) { cc_log("Cleaning up cache directory %s", dir); - cache_size_threshold = conf->max_size * LIMIT_MULTIPLE / 16; - files_in_cache_threshold = conf->max_files * LIMIT_MULTIPLE / 16; + /* + * When "max files" or "max cache size" is reached, one of the 16 cache + * subdirectories is cleaned up. When doing so, files are deleted (in LRU + * order) until the levels are below limit_multiple. + */ + cache_size_threshold = conf->max_size * conf->limit_multiple / 16; + files_in_cache_threshold = conf->max_files * conf->limit_multiple / 16; num_files = 0; cache_size = 0; @@ -250,7 +250,7 @@ wipe_dir(struct conf *conf, const char *dir) { cc_log("Clearing out cache directory %s", dir); - files_in_cache_threshold = conf->max_files * LIMIT_MULTIPLE / 16; + files_in_cache_threshold = conf->max_files * conf->limit_multiple / 16; files_in_cache = 0; traverse(dir, wipe_fn); diff --git a/conf.c b/conf.c index aafb0e3e2..1dad62b30 100644 --- a/conf.c +++ b/conf.c @@ -59,6 +59,23 @@ parse_env_string(const char *str, void *result, char **errmsg) return *value != NULL; } +static bool +parse_float(const char *str, void *result, char **errmsg) +{ + float *value = (float *)result; + float x; + char *endptr; + errno = 0; + x = strtof(str, &endptr); + if (errno == 0 && *str != '\0' && *endptr == '\0') { + *value = x; + return true; + } else { + *errmsg = format("invalid floating point: \"%s\"", str); + return false; + } +} + static bool parse_size(const char *str, void *result, char **errmsg) { @@ -309,6 +326,7 @@ conf_create(void) conf->hash_dir = true; conf->ignore_headers_in_manifest = x_strdup(""); conf->keep_comments_cpp = false; + conf->limit_multiple = 0.8f; conf->log_file = x_strdup(""); conf->max_files = 0; conf->max_size = (uint64_t)5 * 1000 * 1000 * 1000; @@ -562,6 +580,9 @@ conf_print_items(struct conf *conf, printer(s, conf->item_origins[find_conf( "keep_comments_cpp")->number], context); + reformat(&s, "limit_multiple = %.1f", (double) conf->limit_multiple); + printer(s, conf->item_origins[find_conf("limit_multiple")->number], context); + reformat(&s, "log_file = %s", conf->log_file); printer(s, conf->item_origins[find_conf("log_file")->number], context); diff --git a/conf.h b/conf.h index e1d0dbd3b..232dcfd55 100644 --- a/conf.h +++ b/conf.h @@ -19,6 +19,7 @@ struct conf { bool hash_dir; char *ignore_headers_in_manifest; bool keep_comments_cpp; + float limit_multiple; char *log_file; unsigned max_files; uint64_t max_size; diff --git a/confitems.gperf b/confitems.gperf index 6b24de25a..531bc92d8 100644 --- a/confitems.gperf +++ b/confitems.gperf @@ -22,18 +22,19 @@ hard_link, 11, ITEM(hard_link, bool) hash_dir, 12, ITEM(hash_dir, bool) ignore_headers_in_manifest, 13, ITEM(ignore_headers_in_manifest, env_string) keep_comments_cpp, 14, ITEM(keep_comments_cpp, bool) -log_file, 15, ITEM(log_file, env_string) -max_files, 16, ITEM(max_files, unsigned) -max_size, 17, ITEM(max_size, size) -path, 18, ITEM(path, env_string) -prefix_command, 19, ITEM(prefix_command, env_string) -prefix_command_cpp, 20, ITEM(prefix_command_cpp, env_string) -read_only, 21, ITEM(read_only, bool) -read_only_direct, 22, ITEM(read_only_direct, bool) -recache, 23, ITEM(recache, bool) -run_second_cpp, 24, ITEM(run_second_cpp, bool) -sloppiness, 25, ITEM(sloppiness, sloppiness) -stats, 26, ITEM(stats, bool) -temporary_dir, 27, ITEM(temporary_dir, env_string) -umask, 28, ITEM(umask, umask) -unify, 29, ITEM(unify, bool) +limit_multiple, 15, ITEM(limit_multiple, float) +log_file, 16, ITEM(log_file, env_string) +max_files, 17, ITEM(max_files, unsigned) +max_size, 18, ITEM(max_size, size) +path, 19, ITEM(path, env_string) +prefix_command, 20, ITEM(prefix_command, env_string) +prefix_command_cpp, 21, ITEM(prefix_command_cpp, env_string) +read_only, 22, ITEM(read_only, bool) +read_only_direct, 23, ITEM(read_only_direct, bool) +recache, 24, ITEM(recache, bool) +run_second_cpp, 25, ITEM(run_second_cpp, bool) +sloppiness, 26, ITEM(sloppiness, sloppiness) +stats, 27, ITEM(stats, bool) +temporary_dir, 28, ITEM(temporary_dir, env_string) +umask, 29, ITEM(umask, umask) +unify, 30, ITEM(unify, bool) diff --git a/confitems_lookup.c b/confitems_lookup.c index 845dfb1d1..74825575b 100644 --- a/confitems_lookup.c +++ b/confitems_lookup.c @@ -31,7 +31,7 @@ #line 8 "confitems.gperf" struct conf_item; -/* maximum key range = 41, duplicates = 0 */ +/* maximum key range = 46, duplicates = 0 */ #ifdef __GNUC__ __inline @@ -45,32 +45,32 @@ confitems_hash (register const char *str, register unsigned int len) { static const unsigned char asso_values[] = { - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 0, 13, 0, - 15, 10, 45, 5, 30, 10, 45, 0, 10, 20, - 5, 0, 0, 45, 5, 0, 10, 15, 45, 45, - 15, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45 + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 0, 13, 0, + 5, 10, 50, 0, 30, 20, 50, 0, 10, 20, + 5, 0, 0, 50, 5, 0, 10, 15, 50, 50, + 20, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50 }; return len + asso_values[(unsigned char)str[1]] + asso_values[(unsigned char)str[0]]; } @@ -87,19 +87,19 @@ confitems_get (register const char *str, register unsigned int len) { enum { - TOTAL_KEYWORDS = 30, + TOTAL_KEYWORDS = 31, MIN_WORD_LENGTH = 4, MAX_WORD_LENGTH = 26, MIN_HASH_VALUE = 4, - MAX_HASH_VALUE = 44 + MAX_HASH_VALUE = 49 }; static const struct conf_item wordlist[] = { {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, -#line 28 "confitems.gperf" - {"path", 18, ITEM(path, env_string)}, +#line 29 "confitems.gperf" + {"path", 19, ITEM(path, env_string)}, {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, #line 13 "confitems.gperf" @@ -114,44 +114,44 @@ confitems_get (register const char *str, register unsigned int len) {"cpp_extension", 7, ITEM(cpp_extension, string)}, #line 14 "confitems.gperf" {"compiler_check", 4, ITEM(compiler_check, string)}, -#line 36 "confitems.gperf" - {"stats", 26, ITEM(stats, bool)}, +#line 37 "confitems.gperf" + {"stats", 27, ITEM(stats, bool)}, #line 12 "confitems.gperf" {"cache_dir_levels", 2, ITEM_V(cache_dir_levels, unsigned, dir_levels)}, #line 16 "confitems.gperf" {"compression_level", 6, ITEM(compression_level, unsigned)}, -#line 25 "confitems.gperf" - {"log_file", 15, ITEM(log_file, env_string)}, -#line 29 "confitems.gperf" - {"prefix_command", 19, ITEM(prefix_command, env_string)}, -#line 35 "confitems.gperf" - {"sloppiness", 25, ITEM(sloppiness, sloppiness)}, +#line 26 "confitems.gperf" + {"log_file", 16, ITEM(log_file, env_string)}, +#line 30 "confitems.gperf" + {"prefix_command", 20, ITEM(prefix_command, env_string)}, +#line 36 "confitems.gperf" + {"sloppiness", 26, ITEM(sloppiness, sloppiness)}, #line 10 "confitems.gperf" {"base_dir", 0, ITEM_V(base_dir, env_string, absolute_path)}, -#line 33 "confitems.gperf" - {"recache", 23, ITEM(recache, bool)}, -#line 30 "confitems.gperf" - {"prefix_command_cpp", 20, ITEM(prefix_command_cpp, env_string)}, +#line 34 "confitems.gperf" + {"recache", 24, ITEM(recache, bool)}, #line 31 "confitems.gperf" - {"read_only", 21, ITEM(read_only, bool)}, -#line 39 "confitems.gperf" - {"unify", 29, ITEM(unify, bool)}, + {"prefix_command_cpp", 21, ITEM(prefix_command_cpp, env_string)}, +#line 32 "confitems.gperf" + {"read_only", 22, ITEM(read_only, bool)}, +#line 40 "confitems.gperf" + {"unify", 30, ITEM(unify, bool)}, {"",0,NULL,0,NULL}, #line 24 "confitems.gperf" {"keep_comments_cpp", 14, ITEM(keep_comments_cpp, bool)}, +#line 28 "confitems.gperf" + {"max_size", 18, ITEM(max_size, size)}, #line 27 "confitems.gperf" - {"max_size", 17, ITEM(max_size, size)}, -#line 26 "confitems.gperf" - {"max_files", 16, ITEM(max_files, unsigned)}, + {"max_files", 17, ITEM(max_files, unsigned)}, {"",0,NULL,0,NULL}, -#line 32 "confitems.gperf" - {"read_only_direct", 22, ITEM(read_only_direct, bool)}, +#line 33 "confitems.gperf" + {"read_only_direct", 23, ITEM(read_only_direct, bool)}, #line 19 "confitems.gperf" {"disable", 9, ITEM(disable, bool)}, -#line 37 "confitems.gperf" - {"temporary_dir", 27, ITEM(temporary_dir, env_string)}, -#line 34 "confitems.gperf" - {"run_second_cpp", 24, ITEM(run_second_cpp, bool)}, +#line 38 "confitems.gperf" + {"temporary_dir", 28, ITEM(temporary_dir, env_string)}, +#line 35 "confitems.gperf" + {"run_second_cpp", 25, ITEM(run_second_cpp, bool)}, {"",0,NULL,0,NULL}, #line 18 "confitems.gperf" {"direct_mode", 8, ITEM(direct_mode, bool)}, @@ -160,8 +160,13 @@ confitems_get (register const char *str, register unsigned int len) {"hash_dir", 12, ITEM(hash_dir, bool)}, #line 21 "confitems.gperf" {"hard_link", 11, ITEM(hard_link, bool)}, -#line 38 "confitems.gperf" - {"umask", 28, ITEM(umask, umask)}, +#line 39 "confitems.gperf" + {"umask", 29, ITEM(umask, umask)}, + {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, + {"",0,NULL,0,NULL}, +#line 25 "confitems.gperf" + {"limit_multiple", 15, ITEM(limit_multiple, float)}, + {"",0,NULL,0,NULL}, #line 23 "confitems.gperf" {"ignore_headers_in_manifest", 13, ITEM(ignore_headers_in_manifest, env_string)}, {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL}, @@ -183,4 +188,4 @@ confitems_get (register const char *str, register unsigned int len) } return 0; } -static const size_t CONFITEMS_TOTAL_KEYWORDS = 30; +static const size_t CONFITEMS_TOTAL_KEYWORDS = 31; diff --git a/envtoconfitems.gperf b/envtoconfitems.gperf index 746cdc206..81d8444ae 100644 --- a/envtoconfitems.gperf +++ b/envtoconfitems.gperf @@ -23,6 +23,7 @@ EXTRAFILES, "extra_files_to_hash" HARDLINK, "hard_link" HASHDIR, "hash_dir" IGNOREHEADERS, "ignore_headers_in_manifest" +LIMIT_MULTIPLE, "limit_multiple" LOGFILE, "log_file" MAXFILES, "max_files" MAXSIZE, "max_size" diff --git a/envtoconfitems_lookup.c b/envtoconfitems_lookup.c index 04aedd72d..1265bd6e6 100644 --- a/envtoconfitems_lookup.c +++ b/envtoconfitems_lookup.c @@ -51,9 +51,9 @@ envtoconfitems_hash (register const char *str, register unsigned int len) 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 10, 0, 0, 10, - 0, 44, 5, 15, 0, 44, 30, 25, 3, 0, - 5, 15, 5, 15, 0, 0, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 20, 0, 0, 10, + 0, 44, 5, 15, 0, 44, 10, 25, 9, 0, + 5, 10, 5, 15, 10, 5, 44, 44, 44, 44, 0, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, @@ -101,7 +101,7 @@ envtoconfitems_get (register const char *str, register unsigned int len) { enum { - TOTAL_KEYWORDS = 30, + TOTAL_KEYWORDS = 31, MIN_WORD_LENGTH = 2, MAX_WORD_LENGTH = 15, MIN_HASH_VALUE = 2, @@ -117,68 +117,69 @@ envtoconfitems_get (register const char *str, register unsigned int len) {"DIR", "cache_dir"}, #line 16 "envtoconfitems.gperf" {"CPP2", "run_second_cpp"}, -#line 40 "envtoconfitems.gperf" - {"UNIFY", "unify"}, + {"",""}, #line 19 "envtoconfitems.gperf" {"DIRECT", "direct_mode"}, #line 20 "envtoconfitems.gperf" {"DISABLE", "disable"}, #line 17 "envtoconfitems.gperf" {"COMMENTS", "keep_comments_cpp"}, -#line 30 "envtoconfitems.gperf" - {"PATH", "path"}, -#line 29 "envtoconfitems.gperf" - {"NLEVELS", "cache_dir_levels"}, #line 31 "envtoconfitems.gperf" + {"PATH", "path"}, +#line 41 "envtoconfitems.gperf" + {"UNIFY", "unify"}, +#line 32 "envtoconfitems.gperf" {"PREFIX", "prefix_command"}, -#line 35 "envtoconfitems.gperf" +#line 36 "envtoconfitems.gperf" {"RECACHE", "recache"}, #line 13 "envtoconfitems.gperf" {"COMPILERCHECK", "compiler_check"}, {"",""}, -#line 32 "envtoconfitems.gperf" - {"PREFIX_CPP", "prefix_command_cpp"}, - {"",""}, -#line 38 "envtoconfitems.gperf" - {"TEMPDIR", "temporary_dir"}, #line 33 "envtoconfitems.gperf" + {"PREFIX_CPP", "prefix_command_cpp"}, +#line 30 "envtoconfitems.gperf" + {"NLEVELS", "cache_dir_levels"}, +#line 27 "envtoconfitems.gperf" + {"LOGFILE", "log_file"}, +#line 34 "envtoconfitems.gperf" {"READONLY", "read_only"}, #line 21 "envtoconfitems.gperf" {"EXTENSION", "cpp_extension"}, -#line 37 "envtoconfitems.gperf" - {"STATS", "stats"}, +#line 40 "envtoconfitems.gperf" + {"UMASK", "umask"}, {"",""}, #line 24 "envtoconfitems.gperf" {"HASHDIR", "hash_dir"}, #line 14 "envtoconfitems.gperf" {"COMPRESS", "compression"}, {"",""}, -#line 34 "envtoconfitems.gperf" +#line 35 "envtoconfitems.gperf" {"READONLY_DIRECT", "read_only_direct"}, {"",""}, -#line 11 "envtoconfitems.gperf" - {"BASEDIR", "base_dir"}, +#line 39 "envtoconfitems.gperf" + {"TEMPDIR", "temporary_dir"}, #line 15 "envtoconfitems.gperf" {"COMPRESSLEVEL", "compression_level"}, +#line 26 "envtoconfitems.gperf" + {"LIMIT_MULTIPLE", "limit_multiple"}, +#line 38 "envtoconfitems.gperf" + {"STATS", "stats"}, {"",""}, -#line 22 "envtoconfitems.gperf" - {"EXTRAFILES", "extra_files_to_hash"}, - {"",""}, -#line 28 "envtoconfitems.gperf" +#line 29 "envtoconfitems.gperf" {"MAXSIZE", "max_size"}, -#line 27 "envtoconfitems.gperf" +#line 28 "envtoconfitems.gperf" {"MAXFILES", "max_files"}, {"",""}, -#line 39 "envtoconfitems.gperf" - {"UMASK", "umask"}, +#line 37 "envtoconfitems.gperf" + {"SLOPPINESS", "sloppiness"}, {"",""}, -#line 26 "envtoconfitems.gperf" - {"LOGFILE", "log_file"}, +#line 11 "envtoconfitems.gperf" + {"BASEDIR", "base_dir"}, #line 23 "envtoconfitems.gperf" {"HARDLINK", "hard_link"}, {"",""}, -#line 36 "envtoconfitems.gperf" - {"SLOPPINESS", "sloppiness"}, +#line 22 "envtoconfitems.gperf" + {"EXTRAFILES", "extra_files_to_hash"}, {"",""}, {"",""}, #line 25 "envtoconfitems.gperf" {"IGNOREHEADERS", "ignore_headers_in_manifest"} @@ -198,4 +199,4 @@ envtoconfitems_get (register const char *str, register unsigned int len) } return 0; } -static const size_t ENVTOCONFITEMS_TOTAL_KEYWORDS = 30; +static const size_t ENVTOCONFITEMS_TOTAL_KEYWORDS = 31; diff --git a/test.sh b/test.sh index c24335bea..2362b96df 100755 --- a/test.sh +++ b/test.sh @@ -186,6 +186,7 @@ TEST() { unset CCACHE_EXTRAFILES unset CCACHE_HARDLINK unset CCACHE_IGNOREHEADERS + unset CCACHE_LIMIT_MULTIPLE unset CCACHE_LOGFILE unset CCACHE_NLEVELS unset CCACHE_NOCPP2 @@ -2647,6 +2648,16 @@ SUITE_cleanup() { $CCACHE -c >/dev/null expect_file_count 1 '.nfs*' $CCACHE_DIR expect_stat 'files in cache' 30 + + # ------------------------------------------------------------------------- + TEST "CCACHE_LIMIT_MULTIPLE" + + prepare_cleanup_test_dir $CCACHE_DIR/a + + # (1/1) * 30 * 16 = 480 + $CCACHE -F 480 >/dev/null + CCACHE_LIMIT_MULTIPLE=0.5 $CCACHE -c >/dev/null + expect_stat 'files in cache' 15 } # ============================================================================= diff --git a/test/framework.c b/test/framework.c index 1eafbcaa1..ccaa7853f 100644 --- a/test/framework.c +++ b/test/framework.c @@ -18,6 +18,8 @@ #include "framework.h" #include "util.h" +#include +#include #if defined(HAVE_TERMIOS_H) #define USE_COLOR #include @@ -170,6 +172,22 @@ cct_check_failed(const char *file, int line, const char *what, fprintf(stderr, "\n"); } +bool +cct_check_float_eq(const char *file, int line, const char *expression, + double expected, double actual) +{ + if (fabs(expected - actual) < DBL_EPSILON) { + cct_check_passed(file, line, expression); + return true; + } else { + char *exp_str = format("%.1f", (double)expected); + char *act_str = format("%.1f", (double)actual); + cct_check_failed(file, line, expression, exp_str, act_str); + free(exp_str); + free(act_str); + return false; + } +} bool cct_check_int_eq(const char *file, int line, const char *expression, int64_t expected, int64_t actual) diff --git a/test/framework.h b/test/framework.h index e8a33bb75..3980a66bf 100644 --- a/test/framework.h +++ b/test/framework.h @@ -82,6 +82,16 @@ } \ } while (false) +#define CHECK_FLOAT_EQ(expected, actual) \ + do { \ + if (!cct_check_float_eq(__FILE__, __LINE__, #actual, (expected), \ + (actual))) { \ + cct_test_end(); \ + cct_suite_end(); \ + return _test_counter; \ + } \ + } while (false) + // ============================================================================ #define CHECK_STR_EQ(expected, actual) \ @@ -122,6 +132,8 @@ void cct_test_end(void); void cct_check_passed(const char *file, int line, const char *assertion); void cct_check_failed(const char *file, int line, const char *assertion, const char *expected, const char *actual); +bool cct_check_float_eq(const char *file, int line, const char *expression, + double expected, double actual); bool cct_check_int_eq(const char *file, int line, const char *expression, int64_t expected, int64_t actual); bool cct_check_str_eq(const char *file, int line, const char *expression, diff --git a/test/test_conf.c b/test/test_conf.c index 560898d65..511c41f42 100644 --- a/test/test_conf.c +++ b/test/test_conf.c @@ -18,7 +18,7 @@ #include "framework.h" #include "util.h" -#define N_CONFIG_ITEMS 30 +#define N_CONFIG_ITEMS 31 static struct { char *descr; const char *origin; @@ -114,6 +114,7 @@ TEST(conf_read_valid_config) "hash_dir = false\n" "ignore_headers_in_manifest = a:b/c\n" "keep_comments_cpp = true\n" + "limit_multiple = 1.0\n" "log_file = $USER${USER} \n" "max_files = 17\n" "max_size = 123M\n" @@ -151,6 +152,7 @@ TEST(conf_read_valid_config) CHECK(!conf->hash_dir); CHECK_STR_EQ("a:b/c", conf->ignore_headers_in_manifest); CHECK(conf->keep_comments_cpp); + CHECK_FLOAT_EQ(1.0, conf->limit_multiple); CHECK_STR_EQ_FREE1(format("%s%s", user, user), conf->log_file); CHECK_INT_EQ(17, conf->max_files); CHECK_INT_EQ(123 * 1000 * 1000, conf->max_size); @@ -376,6 +378,7 @@ TEST(conf_print_items) .hash_dir = false, "ihim", true, + 0.0, "lf", 4711, 98.7 * 1000 * 1000, @@ -425,6 +428,7 @@ TEST(conf_print_items) CHECK_STR_EQ("ignore_headers_in_manifest = ihim", received_conf_items[n++].descr); CHECK_STR_EQ("keep_comments_cpp = true", received_conf_items[n++].descr); + CHECK_STR_EQ("limit_multiple = 0.0", received_conf_items[n++].descr); CHECK_STR_EQ("log_file = lf", received_conf_items[n++].descr); CHECK_STR_EQ("max_files = 4711", received_conf_items[n++].descr); CHECK_STR_EQ("max_size = 98.7M", received_conf_items[n++].descr);