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 08D5B6EC58; Sat, 20 Feb 2021 12:03:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 08D5B6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1613811823; bh=ggdLU6JSCl3K5oLO4/aH6c3A+tk5XlrAC8yqqc6L2SY=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=h3lvAYyjLEXgTm7cItEQ9L8AXY0+/JsUs4SYVtqVROQ09wSCEfvZOMXQ62S8Y8pH+ kMKXUHochx3Kg8+x5ejW/NhpWF9JUOs1HHA/9B9HUElfOUK9wr8xmfqJh/wd+7p4g0 PH4ae0S3igC130U6iNsO1621qJQ8Cp4hes6D5duU= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 32C276EC58 for ; Sat, 20 Feb 2021 12:03:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 32C276EC58 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lDOAv-0000vd-5H; Sat, 20 Feb 2021 12:03:41 +0300 To: Artem Starshov , Alexander Turenko References: <7a1f0cb7a97b41b3cde25ac5d2c591a84aa13f0b.1613674486.git.artemreyt@tarantool.org> Message-ID: Date: Sat, 20 Feb 2021 12:03:40 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <7a1f0cb7a97b41b3cde25ac5d2c591a84aa13f0b.1613674486.git.artemreyt@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD975C3EC174F56692254B0AABE1FB071B2BA6557555153D6A0182A05F53808504020C8E88486FDEF4867E024EFAD944C5341240C0CC0BCF11770D31D7FEE058114 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74EC61905B8C6A847EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063752AC809489EC5B9C8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC4DA53628E3912B41F7CBF7A3FF7B8EA663FB4551B5457752389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0A3E989B1926288338941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B65FF0BFC5AEE34BE6CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC53A69B3AC30C7B9475ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E735BFC944FC657CDB72C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F8DB212830C5B42F72623479134186CDE6BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A59804E413EAF38372DB571F90C301DF47EA0ABFFA47CB3226D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75448CF9D3A7B2C848410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34697E0FA301E28215DE082658905B1669CD67E01C1B1D32BC5C62383A0D6AA9E7AA13E3694F0FB0531D7E09C32AA3244CC192E438EADCD55AFF6B6059AC352C7C3A92A9747B6CC886927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj2CfMKaWP9xtEkvlU4epqxA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822328E9DEA07CE2B12F716E271E540ADA4DD788429FD8613638ED9BB8B05EE7B3AFB559BB5D741EB96D19CD4E7312BAA970A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [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: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hello, thanks for the patch! see my comments below On 18.02.2021 22:30, Artem Starshov wrote: > 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) 1. What happen if someone set boolean value to "False"? May be it's worth to convert env_value to lowercase and then compare? The same question for "true". > + 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( 2. variable name should reflect a purpose of variable. name is about script file, when variable contains a path to a file. > + 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)