From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id B6B496F3C0; Thu, 11 Mar 2021 15:06:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B6B496F3C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1615464384; bh=dRwDAqHr5uKNAYgoDjIzvnrsRDLLREeurH9mhjsJnDQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rqqqYGlQvA3qhEAApj+Rq0LOtdrlm+zbcV45wjJVicVTt0EgEPlEHJuVgaJOx/6sg +QXG2llmvn8V+dai35CU1Y6mDyc8FRThkxYavBjM0qvS1D4N/U5D20zS2p2zZCzu2z AhtkrVwOWnGiDeqHZ9mgDvuPcc2ncM98oyeYYVk0= Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 11E346F3C4 for ; Thu, 11 Mar 2021 15:05:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 11E346F3C4 Received: by smtp56.i.mail.ru with esmtpa (envelope-from ) id 1lKK4f-0001W0-Lp; Thu, 11 Mar 2021 15:05:54 +0300 To: Alexander Turenko , Leonid Vasiliev Date: Thu, 11 Mar 2021 15:05:48 +0300 Message-Id: <804e084d08a18a48c0aeb29bf8c278f5893ea379.1615463815.git.artemreyt@tarantool.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D3134714A9BDB69BE66984610072BB1D09A72A4B5C8F966400894C459B0CD1B922035EC74482A3479B5B2AD66C7424C266ECB7D3664F72D49FE7245B80CF8774 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE768BD42809A772457EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063719513F03911326708638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C11F5982A89E0728C048AD4DA0E8B7A8D30B166A548372880A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE77A825AB47F0FC8649FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3E478A468B35FE767117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF52AE7FAEF113C5EABA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B6C9E7AC32557D0A3E76E601842F6C81A1F004C90652538430CDED94BCBF13EF3B93EC92FD9297F6718AA50765F79006373BA04B6A498D0BA467F23339F89546C5A8DF7F3B2552694A6FED454B719173D6725E5C173C3A84C3CDD845A7E6742F4735872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C9DE2850DD75B2526BE5BFE6E7EFDEDCD789D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C11F5982A89E0728C048AD4DA0E8B7A8D30B166A5483728809C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F0A5F58274334C95F7E59974CDD90CE896BD86E48076A66FD51654AE7A3EA7EB384E46C60FACB67F1D7E09C32AA3244C70C8EC8A1D9129D3615615CCB3071C0F8894E9C85370243E83B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXgFkAEGrNTi7z3l2Fo7L5Az X-Mailru-Sender: 65CD03CFE33A0EC78F35AC4B367C11FE9AF10AC48F6C7601651945E9240E54517CD86A2904C1AE7392F02B39BF137DED0A8ED71B308007E347E5C1256AE813B3E2FBE92986FDCCC89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: [Tarantool-patches] [PATCHv4 1/2] core: add setting error injections via env X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Artem Starshov via Tarantool-patches Reply-To: Artem Starshov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sometimes, it's useful to set error injections via environment variables and this commit adds this opportunity. e.g: `ERRINJ_WAL_WRITE=true tarantool` will be launched with ERRINJ_WAL_WRITE setted to true. Errinjs with bool parameters can be set to "true", "false", "True", "False", "TRUE", "FALSE", etc. (case-insensitive variable). Errinjs with int or double parameters should be whole valid ("123s" is invalid). e.g. for int or double: "123", "-1", "2.34", "+2.34". NOTE: errinjs should work only in debug mode, so added `release_disabled` in suite.ini. But there is a bug in test-run: `release_disable` disables tests at each build type. Partially this problem is descripted in tarantool/test-run#199. Part of #5040 --- src/lib/core/errinj.c | 37 +++++++++++++++++++ src/lib/core/errinj.h | 5 +++ src/main.cc | 3 ++ .../errinj_set_with_enviroment_vars.test.lua | 29 +++++++++++++++ ...errinj_set_with_enviroment_vars_script.lua | 34 +++++++++++++++++ test/box-tap/suite.ini | 1 + 6 files changed, 109 insertions(+) create mode 100755 test/box-tap/errinj_set_with_enviroment_vars.test.lua create mode 100644 test/box-tap/errinj_set_with_enviroment_vars_script.lua diff --git a/src/lib/core/errinj.c b/src/lib/core/errinj.c index d3aa0ca4f..5afbd1839 100644 --- a/src/lib/core/errinj.c +++ b/src/lib/core/errinj.c @@ -28,9 +28,11 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#include #include #include #include +#include #include #include "trivia/config.h" @@ -66,3 +68,38 @@ int errinj_foreach(errinj_cb cb, void *cb_ctx) { } return 0; } + +void errinj_set_with_environment_vars(void) { + for (enum errinj_id i = 0; i < errinj_id_MAX; i++) { + struct errinj *inj = &errinjs[i]; + const char *env_value = getenv(inj->name); + if (env_value == NULL || *env_value == '\0') + continue; + + if (inj->type == ERRINJ_INT) { + char *end; + int64_t int_value = strtoll(env_value, &end, 10); + if (*end == '\0') + inj->iparam = int_value; + else + panic("Incorrect value for integer %s: %s", + inj->name, env_value); + } else if (inj->type == ERRINJ_BOOL) { + if (strcasecmp(env_value, "false") == 0) + inj->bparam = false; + else if (strcasecmp(env_value, "true") == 0) + inj->bparam = true; + else + panic("Incorrect value for boolean %s: %s", + inj->name, env_value); + } else if (inj->type == ERRINJ_DOUBLE) { + char *end; + double double_value = strtod(env_value, &end); + if (*end == '\0') + inj->dparam = double_value; + else + panic("Incorrect value for double %s: %s", + inj->name, env_value); + } + } +} diff --git a/src/lib/core/errinj.h b/src/lib/core/errinj.h index 814c57c2e..10edbe2b9 100644 --- a/src/lib/core/errinj.h +++ b/src/lib/core/errinj.h @@ -168,6 +168,11 @@ typedef int (*errinj_cb)(struct errinj *e, void *cb_ctx); int errinj_foreach(errinj_cb cb, void *cb_ctx); +/** + * Set injections by scanning ERRINJ_$(NAME) in environment variables + */ +void errinj_set_with_environment_vars(void); + #ifdef NDEBUG # define ERROR_INJECT(ID, CODE) # define ERROR_INJECT_WHILE(ID, CODE) diff --git a/src/main.cc b/src/main.cc index f3edc4305..c322d2d90 100644 --- a/src/main.cc +++ b/src/main.cc @@ -717,6 +717,9 @@ main(int argc, char **argv) if (res != 0) say_warn("No enough memory for setup ssl certificates paths"); +#ifndef NDEBUG + errinj_set_with_environment_vars(); +#endif tarantool_lua_init(tarantool_bin, main_argc, main_argv); start_time = ev_monotonic_time(); diff --git a/test/box-tap/errinj_set_with_enviroment_vars.test.lua b/test/box-tap/errinj_set_with_enviroment_vars.test.lua new file mode 100755 index 000000000..79f770ab7 --- /dev/null +++ b/test/box-tap/errinj_set_with_enviroment_vars.test.lua @@ -0,0 +1,29 @@ +#!/usr/bin/env tarantool +local fio = require('fio') + +-- Execute errinj_set_with_enviroment_vars_script.lua +-- via tarantool with presetted environment variables. +local TARANTOOL_PATH = arg[-1] +local bool_env = 'ERRINJ_TESTING=true ' .. + 'ERRINJ_WAL_IO=True ' .. + 'ERRINJ_WAL_SYNC=TRUE ' .. + 'ERRINJ_WAL_WRITE=false ' .. + 'ERRINJ_INDEX_ALLOC=False ' .. + 'ERRINJ_WAL_WRITE_DISK=FALSE' +local integer_env = 'ERRINJ_WAL_WRITE_PARTIAL=2 ' .. + 'ERRINJ_WAL_FALLOCATE=+2 ' .. + 'ERRINJ_WAL_WRITE_COUNT=-2' +local double_env = 'ERRINJ_VY_READ_PAGE_TIMEOUT=2.5 ' .. + 'ERRINJ_VY_SCHED_TIMEOUT=+2.5 ' .. + 'ERRINJ_RELAY_TIMEOUT=-2.5' +local set_env_str = ('%s %s %s'):format(bool_env, integer_env, double_env) +local path_to_test_file = fio.pathjoin( + os.getenv('PWD'), + 'box-tap', + 'errinj_set_with_enviroment_vars_script.lua') +local shell_command = ('%s %s %s'):format( + set_env_str, + TARANTOOL_PATH, + path_to_test_file) + +os.exit(os.execute(shell_command)) diff --git a/test/box-tap/errinj_set_with_enviroment_vars_script.lua b/test/box-tap/errinj_set_with_enviroment_vars_script.lua new file mode 100644 index 000000000..f15085aa0 --- /dev/null +++ b/test/box-tap/errinj_set_with_enviroment_vars_script.lua @@ -0,0 +1,34 @@ +-- Script for box-tap/errinj_set_with_enviroment_vars.test.lua test. + +local tap = require('tap') +local errinj = box.error.injection + +local test = tap.test('set errinjs via environment variables') + +test:plan(3) + +test:test('Set boolean error injections', function(test) + test:plan(6) + test:is(errinj.get('ERRINJ_TESTING'), true, 'true') + test:is(errinj.get('ERRINJ_WAL_IO'), true, 'True') + test:is(errinj.get('ERRINJ_WAL_SYNC'), true, 'TRUE') + test:is(errinj.get('ERRINJ_WAL_WRITE'), false, 'false') + test:is(errinj.get('ERRINJ_INDEX_ALLOC'), false, 'False') + test:is(errinj.get('ERRINJ_WAL_WRITE_DISK'), false, 'FALSE') +end) + +test:test('Set integer error injections', function(test) + test:plan(3) + test:is(errinj.get('ERRINJ_WAL_WRITE_PARTIAL'), 2, '2') + test:is(errinj.get('ERRINJ_WAL_FALLOCATE'), 2, '+2') + test:is(errinj.get('ERRINJ_WAL_WRITE_COUNT'), -2, '-2') +end) + +test:test('Set double error injections', function(test) + test:plan(3) + test:is(errinj.get('ERRINJ_VY_READ_PAGE_TIMEOUT'), 2.5, "2.5") + test:is(errinj.get('ERRINJ_VY_SCHED_TIMEOUT'), 2.5, "+2.5") + test:is(errinj.get('ERRINJ_RELAY_TIMEOUT'), -2.5, "-2.5") +end) + +os.exit(test:check() and 0 or 1) diff --git a/test/box-tap/suite.ini b/test/box-tap/suite.ini index a7c03baa8..8ed7fffb9 100644 --- a/test/box-tap/suite.ini +++ b/test/box-tap/suite.ini @@ -4,6 +4,7 @@ description = Database tests with #! using TAP is_parallel = True pretest_clean = True use_unix_sockets_iproto = True +release_disabled = errinj_set_with_enviroment_vars.test.lua config = suite.cfg fragile = { "retries": 10, -- 2.28.0