Skip to content

Commit

Permalink
Add an option to disable parsing of debug point instructions (#697)
Browse files Browse the repository at this point in the history
Added an option that can be passed into the TDViaParser to instruct it to skip parsing the DebugPoint instructions. Made changes to the eggshell loadVia call as well so that the disable debugging option can be passed in.

Added tests for the new option.
  • Loading branch information
shivaprasad-basavaraj authored Dec 13, 2021
1 parent f36a2b6 commit 66544bc
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 55 deletions.
16 changes: 10 additions & 6 deletions source/CommandLine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ int VIREO_MAIN(int argc, const char * argv[])
if (argc >= 2) {
gShells._pRootShell = TypeManager::New(nullptr);

Boolean debugging = false;
for (Int32 arg = 1; arg < argc; ++arg) {
if (strcmp(argv[arg], "-D") == 0) {
gShells._pRootShell->DumpPrimitiveDictionary();
continue;
} else if (strcmp(argv[arg], "--debugging")) {
debugging = true;
}
}

gShells._pUserShell = TypeManager::New(gShells._pRootShell);
TypeManagerScope scope(gShells._pUserShell);
for (Int32 arg = 1; arg < argc; ++arg) {
fileName.AliasAssignCStr(argv[arg]);
if (fileName.Length() && argv[arg][0] != '-') {
gShells._pUserShell = TypeManager::New(gShells._pRootShell);
TypeManagerScope scope(gShells._pUserShell);
// Nested scope so that buffer is cleaned up before userShell continues running.
{
STACK_VAR(String, fileBuffer);
Expand All @@ -62,7 +66,7 @@ int VIREO_MAIN(int argc, const char * argv[])

SubString fileString = fileBuffer.Value->MakeSubStringAlias();
gShells._keepRunning = true;
if (TDViaParser::StaticRepl(gShells._pUserShell, &fileString) != kNIError_Success) {
if (TDViaParser::StaticRepl(gShells._pUserShell, &fileString, debugging) != kNIError_Success) {
gShells._keepRunning = false;
}

Expand All @@ -79,9 +83,9 @@ int VIREO_MAIN(int argc, const char * argv[])
RunExec(); // deletes TypeManagers on exit
}
#endif
LOG_PLATFORM_MEM("Mem after execution")
gShells._pUserShell->Delete();
}
LOG_PLATFORM_MEM("Mem after execution")
gShells._pUserShell->Delete();
}
gShells._pRootShell->Delete();
LOG_PLATFORM_MEM("Mem after cleanup")
Expand Down
4 changes: 2 additions & 2 deletions source/core/CEntryPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ VIREO_EXPORT void* EggShell_Create(TypeManagerRef parent)
return TypeManager::New(parent);
}
//------------------------------------------------------------
VIREO_EXPORT NIError EggShell_REPL(TypeManagerRef tm, const Utf8Char* commands, Int32 length)
VIREO_EXPORT NIError EggShell_REPL(TypeManagerRef tm, const Utf8Char* commands, Int32 length, Boolean debugging)
{
if (length == -1) {
length = (Int32)strlen((const char*)commands);
}
SubString input(commands, commands + length);
NIError err = TDViaParser::StaticRepl(tm, &input);
NIError err = TDViaParser::StaticRepl(tm, &input, debugging);
return err;
}
//------------------------------------------------------------
Expand Down
26 changes: 19 additions & 7 deletions source/core/TDCodecVia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ namespace Vireo
//------------------------------------------------------------
TDViaParser::TDViaParser(TypeManagerRef typeManager, SubString *typeString, EventLog *pLog,
Int32 lineNumberBase, SubString* format, Boolean jsonLVExt /*=false*/, Boolean strictJSON /*=false*/,
Boolean quoteInfNaN /*= false*/, Boolean allowJSONNulls /*= false*/)
Boolean quoteInfNaN /*= false*/, Boolean allowJSONNulls /*= false*/, Boolean debugging /*= false*/)
{
_pLog = pLog;
_typeManager = typeManager;
_string.AliasAssign(typeString);
_originalStart = typeString->Begin();
_lineNumberBase = lineNumberBase;
_loadVIsImmediately = false;
_debugging = debugging;
_options._allowNulls = allowJSONNulls;
_virtualInstrumentScope = nullptr;

Expand Down Expand Up @@ -227,7 +228,7 @@ TypeRef TDViaParser::ParseRequire()
gPlatform.IO.Printf("(Error \"Package <%.*s> empty\")\n", FMT_LEN_BEGIN(&moduleName));
} else {
TypeManagerScope scope(newTADM);
TDViaParser parser(newTADM, &module, _pLog, CalcCurrentLine());
TDViaParser parser(newTADM, &module, _pLog, CalcCurrentLine(), nullptr, false, false, false, false, _debugging);
parser.ParseREPL();
}
}
Expand Down Expand Up @@ -263,7 +264,7 @@ TypeRef TDViaParser::ParseContext()
// Parse the subExpression using the newly created type manager.
{
TypeManagerScope scope(newTADM);
TDViaParser parser(newTADM, &_string, _pLog, CalcCurrentLine());
TDViaParser parser(newTADM, &_string, _pLog, CalcCurrentLine(), nullptr, false, false, false, false, _debugging);
parser.ParseREPL();
_string.AliasAssign(parser.TheString());
}
Expand Down Expand Up @@ -1609,7 +1610,8 @@ void TDViaParser::FinalizeVILoad(VirtualInstrument* vi, EventLog* pLog)
// Int32 startingAllocations = vi->TheTypeManager()->_totalAllocations;
#endif
EventLog dummyLog(EventLog::DevNull);
TDViaParser parser(vi->TheTypeManager(), &clumpSource, &dummyLog, vi->_lineNumberBase);
TDViaParser parser(vi->TheTypeManager(), &clumpSource, &dummyLog, vi->_lineNumberBase,
nullptr, false, false, false, false, _debugging);
for (; pClump < pClumpEnd; pClump++) {
parser.ParseClump(pClump, &cia);
}
Expand All @@ -1627,7 +1629,8 @@ void TDViaParser::FinalizeVILoad(VirtualInstrument* vi, EventLog* pLog)

{
// (3) Parse a second time, instructions will be allocated out of the chunk.
TDViaParser parser(vi->TheTypeManager(), &clumpSource, pLog, vi->_lineNumberBase);
TDViaParser parser(vi->TheTypeManager(), &clumpSource, pLog, vi->_lineNumberBase,
nullptr, false, false, false, false, _debugging);
for (; pClump < pClumpEnd; pClump++) {
parser.ParseClump(pClump, &cia);
}
Expand Down Expand Up @@ -1736,6 +1739,15 @@ void TDViaParser::ParseClump(VIClump* viClump, InstructionAllocator* cia)
if (!_string.EatChar(')'))
return LOG_EVENT(kHardDataError, "')' missing");
state.MarkPerch(&perchName);
} else if (instructionNameToken.CompareCStr("DebugPoint") && !_debugging) {
// No -Op
if (!_string.EatChar('('))
return LOG_EVENT(kHardDataError, "'(' missing");
// Skip over the DebugPoint arguments
SubString skipTokens;
do {
_string.ReadToken(&skipTokens);
} while (!skipTokens.CompareCStr(")"));
} else {
instructionNameToken.TrimQuotedString(tt);
Boolean keepTrying = state.StartInstruction(&instructionNameToken) != nullptr;
Expand Down Expand Up @@ -1888,14 +1900,14 @@ void TDViaParser::FinalizeModuleLoad(TypeManagerRef tm, EventLog* pLog)
}
//------------------------------------------------------------
//! Create a parser and process all the declarations in the stream.
NIError TDViaParser::StaticRepl(TypeManagerRef tm, SubString *replStream)
NIError TDViaParser::StaticRepl(TypeManagerRef tm, SubString *replStream, Boolean debugging)
{
TypeManagerScope scope(tm);

STACK_VAR(String, errorLog);
EventLog log(errorLog.Value);

TDViaParser parser(tm, replStream, &log, 1);
TDViaParser parser(tm, replStream, &log, 1, nullptr, false, false, false, false, debugging);
NIError err = parser.ParseREPL();

if (errorLog.Value->Length() > 0) {
Expand Down
2 changes: 1 addition & 1 deletion source/include/CEntryPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef enum {
//! TypeManager functions
VIREO_EXPORT Int32 Vireo_MaxExecWakeUpTime();
VIREO_EXPORT void* EggShell_Create(TypeManagerRef parent);
VIREO_EXPORT NIError EggShell_REPL(TypeManagerRef tm, const Utf8Char* commands, Int32 length);
VIREO_EXPORT NIError EggShell_REPL(TypeManagerRef tm, const Utf8Char* commands, Int32 length, Boolean debugging);
VIREO_EXPORT Int32 EggShell_ExecuteSlices(TypeManagerRef tm, Int32 numSlices, Int32 millisecondsToRun);
VIREO_EXPORT TypeRef EggShell_GetTypeList(TypeManagerRef tm);
VIREO_EXPORT void EggShell_Delete(TypeManagerRef tm);
Expand Down
9 changes: 5 additions & 4 deletions source/include/TDCodecVia.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class TDViaParser
const Utf8Char* _originalStart;
VirtualInstrument *_virtualInstrumentScope; // holds the current (innermost) VI during parsing
Int32 _lineNumberBase;
Boolean _debugging;

public:
// Format options also used in ViaFormatter
Expand All @@ -112,7 +113,7 @@ class TDViaParser

TDViaParser(TypeManagerRef typeManager, SubString* typeString, EventLog *pLog, Int32 lineNumberBase,
SubString* format = nullptr, Boolean jsonLVExt = false, Boolean strictJSON = false,
Boolean quoteInfNaN = false, Boolean allowJSONNulls = false);
Boolean quoteInfNaN = false, Boolean allowJSONNulls = false, Boolean debugging = false);
void Reset() { _string.AliasAssign(_originalStart, _string.End()); }
TypeRef ParseType(TypeRef patternType = nullptr);
TypeRef ParseLiteral(TypeRef patternType);
Expand All @@ -129,11 +130,11 @@ class TDViaParser
void PreParseClump(VIClump* viClump);
SubString* TheString() {return &_string;}
VirtualInstrument *CurrentVIScope() const { return _virtualInstrumentScope; }
void FinalizeVILoad(VirtualInstrument* vi, EventLog* pLog);
void FinalizeModuleLoad(TypeManagerRef tm, EventLog* pLog);

public:
static NIError StaticRepl(TypeManagerRef tm, SubString *replStream);
static void FinalizeVILoad(VirtualInstrument* vi, EventLog* pLog);
static void FinalizeModuleLoad(TypeManagerRef tm, EventLog* pLog);
static NIError StaticRepl(TypeManagerRef tm, SubString *replStream, Boolean debugging = false);

private:
TypeRef BadType() const {return _typeManager->BadType();}
Expand Down
5 changes: 3 additions & 2 deletions source/io/module_eggShell.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ var assignEggShell;
return str;
};

Module.eggShell.loadVia = publicAPI.eggShell.loadVia = function (viaText) {
Module.eggShell.loadVia = publicAPI.eggShell.loadVia = function (viaText, config) {
if (typeof viaText !== 'string') {
throw new Error('Expected viaText to be a string');
}
Expand All @@ -705,7 +705,8 @@ var assignEggShell;
origPrintErr(textErr);
};

var result = Module._EggShell_REPL(Module.eggShell.v_userShell, viaTextPointer, viaTextLength);
var debugging = (config && typeof config.debugging === 'boolean') ? config.debugging : false;
var result = Module._EggShell_REPL(Module.eggShell.v_userShell, viaTextPointer, viaTextLength, debugging);
Module._free(viaTextPointer);
Module.print = origPrint;
Module.printErr = origPrintErr;
Expand Down
85 changes: 57 additions & 28 deletions test-it/karma/debugpoint/DebugPoint.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,67 @@ describe('A via file with debug point ', function () {
const simpleAddNodeViaUrl = fixtures.convertToAbsoluteFromFixturesDir('debugpoint/SimpleAddNode.via');
const addNodeWithCaseStructureViaUrl = fixtures.convertToAbsoluteFromFixturesDir('debugpoint/AddNodeWithCaseStructure.via');

beforeAll(function (done) {
fixtures.preloadAbsoluteUrls([
simpleAddNodeViaUrl,
addNodeWithCaseStructureViaUrl
], done);
});
describe('and debugging enabled, ', function () {
beforeAll(function (done) {
fixtures.preloadAbsoluteUrls([
simpleAddNodeViaUrl,
addNodeWithCaseStructureViaUrl
], done);
});

beforeAll(async function () {
vireo = await vireoHelpers.createInstance();
});
beforeAll(async function () {
vireo = await vireoHelpers.createInstance();
});

afterAll(function () {
vireo = undefined;
});
afterAll(function () {
vireo = undefined;
});

it('on executing succesfully set the needs update property on corresponding local ', async function () {
const runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, simpleAddNodeViaUrl, {debugging: true});
const resultLocal = vireo.eggShell.findValueRef('MyVI', 'local3');
expect(vireo.eggShell.testNeedsUpdateAndReset(resultLocal)).toBeFalse();
const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(vireo.eggShell.testNeedsUpdateAndReset(resultLocal)).toBeTrue();
});

it('on executing succesfully set the needs update property on corresponding local ', async function () {
const runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, simpleAddNodeViaUrl);
const sumIndicator = vireo.eggShell.findValueRef('MyVI', 'dataItem_Sum');
expect(vireo.eggShell.testNeedsUpdateAndReset(sumIndicator)).toBeFalse();
const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(vireo.eggShell.testNeedsUpdateAndReset(sumIndicator)).toBeTrue();
it('on not executing will not set the needs update property on corresponding local', async function () {
const runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, addNodeWithCaseStructureViaUrl, {debugging: true});
const resultLocal = vireo.eggShell.findValueRef('MyVI', 'local7');
expect(vireo.eggShell.testNeedsUpdateAndReset(resultLocal)).toBeFalse();
const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(vireo.eggShell.testNeedsUpdateAndReset(resultLocal)).toBeFalse();
});
});

it('on not executing will not set the needs update property on corresponding local', async function () {
const runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, addNodeWithCaseStructureViaUrl);
const sumIndicator = vireo.eggShell.findValueRef('MyVI', 'dataItem_Sum');
expect(vireo.eggShell.testNeedsUpdateAndReset(sumIndicator)).toBeFalse();
const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(vireo.eggShell.testNeedsUpdateAndReset(sumIndicator)).toBeFalse();
describe('and debugging disabled, ', function () {
beforeAll(function (done) {
fixtures.preloadAbsoluteUrls([
simpleAddNodeViaUrl,
addNodeWithCaseStructureViaUrl
], done);
});

beforeAll(async function () {
vireo = await vireoHelpers.createInstance();
});

afterAll(function () {
vireo = undefined;
});

it('on executing succesfully will not set the needs update property on corresponding local ', async function () {
const runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, simpleAddNodeViaUrl);
const resultLocal = vireo.eggShell.findValueRef('MyVI', 'local3');
expect(vireo.eggShell.testNeedsUpdateAndReset(resultLocal)).toBeFalse();
const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(vireo.eggShell.testNeedsUpdateAndReset(resultLocal)).toBeFalse();
});
});
});
4 changes: 2 additions & 2 deletions test-it/karma/utilities/TestHelpers.VireoRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';
window.testHelpers = window.testHelpers || {};

var rebootAndLoadVia = function (vireo, viaAbsolutePath) {
var rebootAndLoadVia = function (vireo, viaAbsolutePath, config) {
// Jasmine Matchers library is not always ready in beforeAll so use jasmine core functions
expect(typeof viaAbsolutePath).toBe('string');
expect(viaAbsolutePath).not.toBe('');
Expand Down Expand Up @@ -39,7 +39,7 @@

var ex;
try {
vireo.eggShell.loadVia(viaText);
vireo.eggShell.loadVia(viaText, config);
} catch (exIn) {
ex = addOutputToError(exIn);
throw ex;
Expand Down
2 changes: 1 addition & 1 deletion test-it/karma/vtrsuite/VtrTestSuite.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('The Vireo VTR test suite', function () {
var vtrText = fixtures.loadAbsoluteUrl(vtrFile);
var runSlicesAsync;
try {
runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, viaFile);
runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, viaFile, {debugging: true});
} catch (ex) {
expect(ex.message).toMatch(/CantDecode/);
expect(ex.rawPrintError).toBeEmptyString();
Expand Down
4 changes: 2 additions & 2 deletions test-it/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
});

try {
vireo.eggShell.loadVia(viaCode);
vireo.eggShell.loadVia(viaCode, {debugging: true});
} catch (ex) {
testFinishedCB(testOutput);
return;
Expand All @@ -271,7 +271,7 @@
}

try {
newResults = cp.execFileSync(exec, [viaPath]).toString();
newResults = cp.execFileSync(exec, [viaPath, '--debugging']).toString();
} catch (e) {
// If Vireo detects an error it will return non zero
// and exec will throw an exception, so catch the results.
Expand Down

0 comments on commit 66544bc

Please sign in to comment.