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 17DE76EC58; Thu, 18 Feb 2021 22:30:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 17DE76EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1613676657; bh=mhrSduUC9QtsiW/NSsVjpFQBK7OgQvyIoYr6v+46df0=; 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=y4G78AFLN1xTi5JIeu8PlBJE3Q+49pai/HIRBKPzDixLJy6U6uwTT4HU0YopM/Cnx j7FP1izs63X8AMXjymfI5aAKTnkKFW0Ct1Hf5GCEcBB2bKvzn8X1yrSv/d5ohMv70x v3M7+HRAhqrFEpGKGa5HoBfHgbwQC8zB+sS3iGfc= Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 6A4AB6EC58 for ; Thu, 18 Feb 2021 22:30:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6A4AB6EC58 Received: by smtp53.i.mail.ru with esmtpa (envelope-from ) id 1lCp0M-0001dz-Gi; Thu, 18 Feb 2021 22:30:26 +0300 To: Alexander Turenko , Sergey Bronnikov Date: Thu, 18 Feb 2021 22:30:18 +0300 Message-Id: <7a1f0cb7a97b41b3cde25ac5d2c591a84aa13f0b.1613674486.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: 4F1203BC0FB41BD975C3EC174F5669228C980786C9DBA186ED94931C77F7596E182A05F538085040D93EB6BC70CEA2215F0262DD15235C3C61A94BF6A448D63A547C18D3925FE3B4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73870E1FF9A049D91EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372FCE560095E3DFB88638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC12ACF8D6BDD292353A59B25919BA4BEED2CC26B3F4760596389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C091DAD9F922AA71188941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B601F8F2FECC0250C8CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249709AF4A8134C0FDA76E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BF428E0D54E2412663AA81AA40904B5D9DBF02ECDB25306B2B25CBF701D1BE8734AD6D5ED66289B5278DA827A17800CE7CA4B174CFBB40A0467F23339F89546C5A8DF7F3B2552694A6FED454B719173D6725E5C173C3A84C3C3E5FCF1FE4BE79D35872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C9DE2850DD75B2526BE5BFE6E7EFDEDCD789D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF81F587C2CCB1933D7FAB0DD2D57F51C8F0AD2B5825C43819C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF31C0090ACECF247D699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3473457D764E1CDE77E26B35C3BC2A48D7D11DD76948404D2A7F43620B3170E0488229FEF86D2D70901D7E09C32AA3244C6B80121F106C824C46F1B09A2A7EE26939C99C45E8D137E983B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXg4WSo14jlZADrs2rLj4jyG X-Mailru-Sender: 65CD03CFE33A0EC7E4F6C6702325C427094F778B4ECEAC84F229E912A474BD7FEA346DCD465ADD55B08A37556DE0CB7BB7E364AFDB3F206FD953F29DB7D76D89B1E6F68DAE724AB9112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCHv2 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 should be set as "true", "TRUE", "false" or "FALSE". 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". Part of #5040 --- src/lib/core/errinj.c | 26 +++++++++++++++++++ src/lib/core/errinj.h | 5 ++++ src/main.cc | 1 + .../errinj_set_with_enviroment_vars.test.lua | 14 ++++++++++ ...errinj_set_with_enviroment_vars_script.lua | 13 ++++++++++ 5 files changed, 59 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..3c1194f20 100644 --- a/src/lib/core/errinj.c +++ b/src/lib/core/errinj.c @@ -66,3 +66,29 @@ int errinj_foreach(errinj_cb cb, void *cb_ctx) { } return 0; } + +void errinj_set_with_environment_vars() { + 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 || *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 if (inj->type == ERRINJ_BOOL) { + if (strcmp(env_value, "false") == 0 || strcmp(env_value, "FALSE") == 0) + inj->bparam = false; + else if (strcmp(env_value, "true") == 0 || strcmp(env_value, "TRUE") == 0) + inj->bparam = true; + } else if (inj->type == ERRINJ_DOUBLE) { + char *end; + double double_value = strtod(env_value, &end); + if (*end == '\0') + inj->dparam = double_value; + } + } +} diff --git a/src/lib/core/errinj.h b/src/lib/core/errinj.h index 814c57c2e..d76aedf7a 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(); + #ifdef NDEBUG # define ERROR_INJECT(ID, CODE) # define ERROR_INJECT_WHILE(ID, CODE) diff --git a/src/main.cc b/src/main.cc index 2fce81bb3..58a660689 100644 --- a/src/main.cc +++ b/src/main.cc @@ -710,6 +710,7 @@ main(int argc, char **argv) memtx_tx_manager_init(); crypto_init(); systemd_init(); + errinj_set_with_environment_vars(); 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..f52ebcc11 --- /dev/null +++ b/test/box-tap/errinj_set_with_enviroment_vars.test.lua @@ -0,0 +1,14 @@ +#!/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 set_env_str = 'ERRINJ_TESTING=true ERRINJ_WAL_WRITE_PARTIAL=1 ERRINJ_VY_READ_PAGE_TIMEOUT=2.5' +local script_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, script_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..b8903b907 --- /dev/null +++ b/test/box-tap/errinj_set_with_enviroment_vars_script.lua @@ -0,0 +1,13 @@ +-- Script for box-tap/errinj_set_with_enviroment_vars.test.lua test. + +local tap = require('tap') +local errinj = box.error.injection + +local res = tap.test('set errinjs via environment variables', function(test) + test:plan(3) + test:is(errinj.get('ERRINJ_TESTING'), true, "set bool error injection") + test:is(errinj.get('ERRINJ_WAL_WRITE_PARTIAL'), 1, "set int error injection") + test:is(errinj.get('ERRINJ_VY_READ_PAGE_TIMEOUT'), 2.5, "set double error injection") +end) + +os.exit(res and 0 or 1) -- 2.28.0