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 155C95AA586; Tue, 15 Aug 2023 12:41:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 155C95AA586 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1692092514; bh=xGZhSTmvwclyTvyKOHenp92g27YCfDGOY1/skR9YGAA=; 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=JqlElne178s7bjbIOMlkb7HdJiqDz7Ngi6xi8FbzueA4rCEGnF0LNgXFCqUjLy9Mz Qyt8+EVSnwJNnjDnjmWdLRvYhYX3otsR06rhof5UEYmSN/zMQdKr/4xuDcDS2+1vBU wcoIs3ZU5DVLbqrvDzRqh6nQtobfLbD+YC/k47fA= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [95.163.41.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DAEE05AA586 for ; Tue, 15 Aug 2023 12:41:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DAEE05AA586 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1qVqYD-009Mi1-1T; Tue, 15 Aug 2023 12:41:21 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Tue, 15 Aug 2023 12:36:27 +0300 Message-ID: <28c7aec4df761b06208cc7ccd9055dd444ed2a70.1692089299.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD969E04B5EED670DC8BEB87106826C459512B2000DD660D84D182A05F538085040DFE106F957F6E39F73301DC292E5090ABD63144B2970BBFF5FF0BAE677C83EAE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A1DB0B089319D380EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A975286280E7A0BD8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D886D72C6495D4A9FFE2027B7746407017117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCE566BBE820FEB67CA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B4AAC223A686B1DECD8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3A5ED62E35AC703CC2D242C3BD2E3F4C6C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407978DA827A17800CE7E4A630A5B664A4FF725E5C173C3A84C3DB8B71E42BA00C4F35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5B769E64026B7984FCEFB152585E389CC7D98463E09CF8E31F87CCE6106E1FC07E67D4AC08A07B9B0672DC5A730DF09D29C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFC94A6A7D3BA7533EDA3E1D5EAF1B7DE01734F406D166663235E4A13138F53804D917AD9EEFBA970E90ABE3E74E35EA6FBF474F8DC4F21DA1EC4E4A0FE0C79B3AA74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJ1ceUZTkowk456hoMQWceA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769BEBC98FEBEF4293673301DC292E5090AD38A1BEA64D5C64ADEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/5] test: introduce `samevalues()` TAP checker 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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" The introduced `samevalues()` helper checks that values in range from 1, to `table.maxn()` of the given table are exactly the same. It may be usefull for test consistency of JIT and VM behaviour. Originally, the `arr_is_consistent()` function was introduced in the . `samevalues()` has the same functionallity (except usage of `table.maxn()` instead `#` operator to be sure, that the table we check isn't a sparse array). --- test/tarantool-tests/gh-6163-min-max.test.lua | 52 ++++++++----------- test/tarantool-tests/tap.lua | 14 +++++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/test/tarantool-tests/gh-6163-min-max.test.lua b/test/tarantool-tests/gh-6163-min-max.test.lua index 63437955..4bc6155c 100644 --- a/test/tarantool-tests/gh-6163-min-max.test.lua +++ b/test/tarantool-tests/gh-6163-min-max.test.lua @@ -2,25 +2,17 @@ local tap = require('tap') local test = tap.test('gh-6163-jit-min-max'):skipcond({ ['Test requires JIT enabled'] = not jit.status(), }) + local x86_64 = jit.arch == 'x86' or jit.arch == 'x64' +-- XXX: table to use for dummy check for some inconsistent results +-- on the x86/64 architecture. +local DUMMY_TAB = {} + test:plan(18) -- -- gh-6163: math.min/math.max inconsistencies. -- -local function isnan(x) - return x ~= x -end - -local function array_is_consistent(res) - for i = 1, #res - 1 do - if res[i] ~= res[i + 1] and not (isnan(res[i]) and isnan(res[i + 1])) then - return false - end - end - return true -end - -- This function creates dirty values on the Lua stack. -- The latter of them is going to be treated as an -- argument by the `math.min/math.max`. @@ -91,14 +83,14 @@ for k = 1, 4 do result[k] = min(min(x, nan), x) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'math.min: reassoc_dup') +test:samevalues(result, 'math.min: reassoc_dup') result = {} for k = 1, 4 do result[k] = max(max(x, nan), x) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'math.max: reassoc_dup') +test:samevalues(result, 'math.max: reassoc_dup') -- If one gets the expression like `math.min(x, math.min(x, nan))`, -- and the `comm_dup` optimization is applied, it results in the @@ -120,7 +112,7 @@ for k = 1, 4 do end -- FIXME: results are still inconsistent for the x86/64 architecture. -- expected: nan nan nan nan -test:ok(array_is_consistent(result) or x86_64, 'math.min: comm_dup_minmax') +test:samevalues(x86_64 and DUMMY_TAB or result, 'math.min: comm_dup_minmax') result = {} for k = 1, 4 do @@ -128,7 +120,7 @@ for k = 1, 4 do end -- FIXME: results are still inconsistent for the x86/64 architecture. -- expected: nan nan nan nan -test:ok(array_is_consistent(result) or x86_64, 'math.max: comm_dup_minmax') +test:samevalues(x86_64 and DUMMY_TAB or result, 'math.max: comm_dup_minmax') -- The following optimization should be disabled: -- (x o k1) o k2 ==> x o (k1 o k2) @@ -139,49 +131,49 @@ for k = 1, 4 do result[k] = min(min(x, 0/0), 1.3) end -- expected: 1.3 1.3 1.3 1.3 -test:ok(array_is_consistent(result), 'math.min: reassoc_minmax_k') +test:samevalues(result, 'math.min: reassoc_minmax_k') result = {} for k = 1, 4 do result[k] = max(max(x, 0/0), 1.1) end -- expected: 1.1 1.1 1.1 1.1 -test:ok(array_is_consistent(result), 'math.max: reassoc_minmax_k') +test:samevalues(result, 'math.max: reassoc_minmax_k') result = {} for k = 1, 4 do result[k] = min(max(nan, 1), 1) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'min-max-case1: reassoc_minmax_left') +test:samevalues(result, 'min-max-case1: reassoc_minmax_left') result = {} for k = 1, 4 do result[k] = min(max(1, nan), 1) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'min-max-case2: reassoc_minmax_left') +test:samevalues(result, 'min-max-case2: reassoc_minmax_left') result = {} for k = 1, 4 do result[k] = max(min(nan, 1), 1) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'max-min-case1: reassoc_minmax_left') +test:samevalues(result, 'max-min-case1: reassoc_minmax_left') result = {} for k = 1, 4 do result[k] = max(min(1, nan), 1) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'max-min-case2: reassoc_minmax_left') +test:samevalues(result, 'max-min-case2: reassoc_minmax_left') result = {} for k = 1, 4 do result[k] = min(1, max(nan, 1)) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'min-max-case1: reassoc_minmax_right') +test:samevalues(result, 'min-max-case1: reassoc_minmax_right') result = {} for k = 1, 4 do @@ -189,14 +181,15 @@ for k = 1, 4 do end -- FIXME: results are still inconsistent for the x86/64 architecture. -- expected: nan nan nan nan -test:ok(array_is_consistent(result) or x86_64, 'min-max-case2: reassoc_minmax_right') +test:samevalues(x86_64 and DUMMY_TAB or result, + 'min-max-case2: reassoc_minmax_right') result = {} for k = 1, 4 do result[k] = max(1, min(nan, 1)) end -- expected: 1 1 1 1 -test:ok(array_is_consistent(result), 'max-min-case1: reassoc_minmax_right') +test:samevalues(result, 'max-min-case1: reassoc_minmax_right') result = {} for k = 1, 4 do @@ -204,7 +197,8 @@ for k = 1, 4 do end -- FIXME: results are still inconsistent for the x86/64 architecture. -- expected: nan nan nan nan -test:ok(array_is_consistent(result) or x86_64, 'max-min-case2: reassoc_minmax_right') +test:samevalues(x86_64 and DUMMY_TAB or result, + 'max-min-case2: reassoc_minmax_right') -- XXX: If we look into the disassembled code of `lj_vm_foldarith()` -- we can see the following: @@ -253,13 +247,13 @@ for k = 1, 4 do result[k] = min(min(7.1, 0/0), 1.1) end -- expected: 1.1 1.1 1.1 1.1 -test:ok(array_is_consistent(result), 'min: fold_kfold_numarith') +test:samevalues(result, 'min: fold_kfold_numarith') result = {} for k = 1, 4 do result[k] = max(max(7.1, 0/0), 1.1) end -- expected: 1.1 1.1 1.1 1.1 -test:ok(array_is_consistent(result), 'max: fold_kfold_numarith') +test:samevalues(result, 'max: fold_kfold_numarith') test:done(true) diff --git a/test/tarantool-tests/tap.lua b/test/tarantool-tests/tap.lua index 8559ee52..af1d4b20 100644 --- a/test/tarantool-tests/tap.lua +++ b/test/tarantool-tests/tap.lua @@ -254,6 +254,19 @@ local function iscdata(test, v, ctype, message, extra) return ok(test, ffi.istype(ctype, v), message, extra) end +local function isnan(v) + return v ~= v +end + +local function samevalues(test, got, message, extra) + for i = 1, table.maxn(got) - 1 do + if got[i] ~= got[i + 1] and not (isnan(got[i]) and isnan(got[i + 1])) then + return fail(test, message, extra) + end + end + return ok(test, true, message, extra) +end + local test_mt local function new(parent, name, fun, ...) @@ -372,6 +385,7 @@ test_mt = { isudata = isudata, iscdata = iscdata, is_deeply = is_deeply, + samevalues = samevalues, like = like, unlike = unlike, } -- 2.41.0