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 218BB6F3E5; Wed, 10 Nov 2021 22:20:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 218BB6F3E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636572048; bh=Bwh9S8SZ6JOJekRXxKzEsg+b9LDpOn0KuyLq3gvpx6Y=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yljEqFG0XXoJJ5qK+2TqQj6tylbHXOHWBJ+KDCydqZNVyBtWZFtoom6hfvHJkDTxg vGZEUFbAQPJjg6/ORdoqPNmjRhH5MMZ44mGNJ9cP3lamlUjbvrlj1zm4BO31lhiXmX BYr62+hPT2WlwdRMUN9Tc7pX+ye9e5ulKyKMsUDA= Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 883B46F3E5 for ; Wed, 10 Nov 2021 22:20:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 883B46F3E5 Received: by mail-lf1-f46.google.com with SMTP id k37so8482309lfv.3 for ; Wed, 10 Nov 2021 11:20:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0w36xE1CqAn40lTFKWkN1ByZntFxrgQ2hJrWnHhj4E4=; b=RjfD+KlrSbVl2CWjNuG7dULpp0u5fev/0IDV9GqWXbCc9KZjDheDwCBf6H1epXKfY9 Ndauu2SMzyV/D4ovw3L8CaVlPBsmqV9qbyWX+Err5OBGNTlMIY003kK9qHT9yko7ra5d 5+iZwtu+qaLpyRRRIzhEjYTssA3MxiVOZLXf7dot1v3HKV6gZJAn0wa6wGcSC86BNiyP 1OlZBW8fviT1enBriYviNxXDzsjLi1soGYC3CWp4R45M6yCs6n0pQVrCpXZbMZDqOJXp boQfTOndE0ru4nToYpwdTIoY+X2YLHVwmWDNtmcE6nIT8KU15b5dl1wlfyV/EogNgjhc ouPw== X-Gm-Message-State: AOAM533QTWF/Ovq1AEZsVIQSdDTrcna2ttwK5qMa1d5Y+J8YOlR0X5M4 5HonubeTCDr/p9LiGYJQOGNcYbTaheBzSt+I X-Google-Smtp-Source: ABdhPJxEzyxpllEu3vRbipsqu8m/89G/985wvjS109AhSGC8weKTlWJSL9mv6ia7KbeceQP3T9ndSA== X-Received: by 2002:a05:6512:607:: with SMTP id b7mr1341618lfe.489.1636572045651; Wed, 10 Nov 2021 11:20:45 -0800 (PST) Received: from localhost.localdomain ([93.175.11.199]) by smtp.gmail.com with ESMTPSA id f15sm55475ljq.137.2021.11.10.11.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 11:20:45 -0800 (PST) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Wed, 10 Nov 2021 22:20:42 +0300 Message-Id: <20211110192042.1687467-1-m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v2] test: adapt tests checking debug line hook trace 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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" The LuaJIT's virtual machine interprets the bytecode following the return from function (i.e. the one succeeding the call made) and located on the line other than that return bytecode, as a new line trigger for line hooks, unlike Lua does. Here is an example (it is joined in one line intend): debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook() This chunk prints for LuaJIT: LINE: 3 LINE: 1 But for Lua 5.1 it is only "LINE: 3" in the output. See also tarantool/tarantool#5693. Those tests are adapted to LuaJIT behavior by changing assertions considering line events that LuaJIT generates. Part of tarantool/tarantool#5870 --- Changes in v2: - Fixed comments as per review by Sergey - Added some comments test/PUC-Rio-Lua-5.1-tests/db.lua | 57 +++++++++++++++++-------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/test/PUC-Rio-Lua-5.1-tests/db.lua b/test/PUC-Rio-Lua-5.1-tests/db.lua index 56f59ea8..120fc04c 100644 --- a/test/PUC-Rio-Lua-5.1-tests/db.lua +++ b/test/PUC-Rio-Lua-5.1-tests/db.lua @@ -8,6 +8,23 @@ do local a=1 end +-- The LuaJIT's virtual machine interprets the bytecode +-- following the return from function (i.e. the one succeeding +-- the call made) and located on the line other than that return +-- bytecode, as a new line trigger for line hooks, unlike Lua +-- does. +-- Here is an example (it is joined in one line intend): +--[[ +debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook() +--]] +-- This chunk prints for LuaJIT: +--[[ +LINE: 3 +LINE: 1 +--]] +-- But for Lua 5.1 it is only "LINE: 3" in the output. +-- See also https://github.com/tarantool/tarantool/issues/5693. +-- This function is modified to correspond with LuaJIT's line triggers. function test (s, l, p) collectgarbage() -- avoid gc during trace local function f (event, line) @@ -16,6 +33,11 @@ function test (s, l, p) if p then print(l, line) end assert(l == line, "wrong trace!!") end + -- Despite `loadstring` and `debug.sethook` are on the same line, LuaJIT + -- generates separate line events for them. The test is adapted to LuaJIT + -- behavior by adding corresponding line numbers into the test table. + table.insert(l, 1, 41) + table.insert(l, 41) debug.sethook(f,"l"); loadstring(s)(); debug.sethook() assert(table.getn(l) == 0) end @@ -25,8 +47,8 @@ do local a = debug.getinfo(print) assert(a.what == "C" and a.short_src == "[C]") local b = debug.getinfo(test, "SfL") - assert(b.name == nil and b.what == "Lua" and b.linedefined == 11 and - b.lastlinedefined == b.linedefined + 10 and + assert(b.name == nil and b.what == "Lua" and b.linedefined == 28 and + b.lastlinedefined == b.linedefined + 15 and b.func == test and not string.find(b.short_src, "%[")) assert(b.activelines[b.linedefined + 1] and b.activelines[b.lastlinedefined]) @@ -95,26 +117,6 @@ repeat assert(g(f) == 'a') until 1 --- FIXME: The LuaJIT's virtual machine interprets the bytecode --- following the return from function (i.e. the one succeeding --- the call made) and located on the line other than that return --- bytecode, as a new line trigger for line hooks, unlike Lua --- does. --- Here is an example (it is joined in one line intend): ---[[ -debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook() ---]] --- This chunk prints for LuaJIT: ---[[ -LINE: 3 -LINE: 1 ---]] --- But for Lua 5.1 it is only "LINE: 3" in the output. --- See also https://github.com/tarantool/tarantool/issues/5693. --- Considering implementation-defined behaviour difference --- (see also https://luajit.org/status.html) test is disabled for --- LuaJIT. ---[=[ test([[if math.sin(1) then @@ -132,23 +134,25 @@ else end ]], {2,5,6}) +-- Test is adapted to the behaviour of LuaJIT. test([[a=1 repeat a=a+1 until a==3 -]], {1,3,4,3,4}) +]], {1,2,3,4,2,3,4}) test([[ do return end ]], {2}) +-- Test is adapted to the behaviour of LuaJIT. test([[local a a=1 while a<=3 do a=a+1 end -]], {2,3,4,3,4,3,4,3,5}) +]], {1,2,3,4,3,4,3,4,3,5}) test([[while math.sin(1) do if math.sin(1) @@ -168,8 +172,9 @@ test([[for i,v in pairs{'a','b'} do end ]], {1,2,1,2,1,3}) -test([[for i=1,4 do a=1 end]], {1,1,1,1,1}) ---]=] +-- Test is adapted to the behaviour of LuaJIT, as it generates only four line +-- events, unlike Lua, which generates five of them. +test([[for i=1,4 do a=1 end]], {1,1,1,1}) print'+' -- 2.33.0