I'm trying to create a flow on 93k with different actions in the if and else branches. The closest thing I've found so far is to test both passed and failed, although this generates two different compare nodes with empty else blocks:
if_passed :some_test_id do
bin 10
end
if_failed :some_test_id do
bin 11
end
Translates to:
if #SOME_TEST_ID_PASSED == 1 then
{
stop_bin "", "fail", , bad, noreprobe, red, 10, over_on;
}
else
{
}
if #SOME_TEST_ID_FAILED == 1 then
{
stop_bin "", "fail", , bad, noreprobe, red, 11, over_on;
}
else
{
}
{
What I'm looking for is something that looks more like this:
if #SOME_TEST_ID_PASSED == 1 then
{
stop_bin "", "fail", , bad, noreprobe, red, 10, over_on;
}
else
{
stop_bin "", "fail", , bad, noreprobe, red, 11, over_on;
}
Is there a way to generate this type of flow structure?
For the kind of example you show, then this is the recommended way to code it:
test :test1, id: :t1
bin 10, if_passed: :t1
bin 11, if_failed: :t1
That's pretty clear and easy to review at the Origen source level. Indeed that will generate with independent T1_PASSED and T1_FAILED branches, which may not be to your taste, but it is logically correct which is the main thing.
The reason we do it that way is because the internal representation which results in that output on the 93K, is easier to target to Teradyne platforms which are row-based and don't really have the concept of if/else logic. So, you get the benefit that anything you can express in Origen is guaranteed to compile for both platforms, but that may be of little consolation if you only need V93K.
Typically though, the more that you use Origen, then the less you care about the generated implementation, similar really to how you don't really care about the generated assembly when you write embedded code in C.
However, it is better if the generated code is easier to follow when you are debugging on the tester, so we are always striving to make the generated output cleaner.
Having said all that, there is a lower-level API which will get close to what you want.
You could manually implement the flag like this:
test :test1, on_fail: { set_flag: :my_flag }, continue: true
if_flag :my_flag do
bin 10
end
unless_flag :my_flag do
bin 11
end
That will generate something like this:
run_and_branch(test1)
then
{
}
else
{
#MY_FLAG = 1;
}
if #MY_FLAG == 1 then
{
stop_bin "", "fail", , bad, noreprobe, red, 10, over_on;
}
else
{
}
if #MY_FLAG == 1 then
{
}
else
{
stop_bin "", "fail", , bad, noreprobe, red, 10, over_on;
}
That's slightly better (from a desired output perspective) since we're down to one flag, but we still have two adjacent conditionals which could/should be collapsed into one.
We actually already have an issue open for that: https://github.com/Origen-SDK/origen_testers/issues/43
Funnily enough I was looking at that earlier tonight, its not implemented yet, but it will be soon.
At that point the output would be:
run_and_branch(test1)
then
{
}
else
{
#MY_FLAG = 1;
}
if #MY_FLAG == 1 then
{
stop_bin "", "fail", , bad, noreprobe, red, 10, over_on;
}
else
{
stop_bin "", "fail", , bad, noreprobe, red, 11, over_on;
}
I would again say though, that consciously structuring the Origen source just to get a particular output is not really the way it should be done, but in this case the source code is not much more complex by being a bit more explicit about it.
Related
I have:
if std::env::consts::OS == "macos" {
// Do something
} else if std::env::consts::OS == "linux" {
// Do the same thing
}
Is there a way I could check for both of these in one line?
You could use the logical "or" operator ||:
if std::env::consts::OS == "macos" || std::env::consts::OS == "linux" {
// Do something
}
Or match, which is a tad more terse in expressing what you want to match, but requires you to cover all possibilities, so a catch-all pattern is required even if you don't want to do anything in that case:
match std::env::consts::OS {
"macos" | "linux" => {
// Do something.
},
_ => {
// No other match arms matched, maybe do something, or don't.
},
};
As a side note, testing what platform you are on is usually a last resort when no other kind of detection will work. It's better to test what capabilities you have than to ask what platform you are on, for two reasons: first, that's the actual question you want to answer, and second, maybe the platforms that don't have that capability right now will sometime later.
I have a command line program where I want to generate a picture given multiple arguments, where the order of the arguments should be respected, and duplicate arguments are allowed
Are there any node.js optstring parsers that would allow for this?
I would like to have something like
generate_picture --red 100 --yellow 200 --red 100 --width 500
And then it generates a "flag" with a red 100px band on top, then a 200px band of yellow, and then another 100px red band, all applied with width 500px
My program doesn't literally do that but it is similar
I think the ideal form that my program would receive these arguments would be an array of arrays like this
[
['red', 100],
['yellow', 200],
['red', 100],
['width', 500]
]
I would probably up-front scan this array-of-arrays for the things i expect to only be applied once like width
I suppose now that I write it out, it might not be too hard to manually parse the process.argv array to get it into this state but curious if there are any options available already
To help my particular circumstance I made this utility function
function parseArgv(argv) {
const map = [];
while (argv.length) {
const val = argv[0].slice(2);
argv = argv.slice(1);
const next = argv.findIndex((arg) => arg.startsWith("-"));
if (next !== -1) {
map.push([val, argv.slice(0, next)]);
argv = argv.slice(next);
} else {
map.push([val, argv]);
break;
}
}
return map;
}
Example usage
test("parse", () => {
expect(
parseArgv(
"--bam file1.bam color:red --vcf variants.vcf --bam file2.bam --defaultSession --out out.svg --fullSvg".split(
" "
)
)
).toEqual([
["bam", ["file1.bam", "color:red"]],
["vcf", ["variants.vcf"]],
["bam", ["file2.bam"]],
["defaultSession", []],
["out", ["out.svg"]],
["fullSvg", []],
]);
});
Then post processing can make a little more sense of this, but this utility function was helpful for my purposes in a way that was not achievable with yargs or other node optstring parsers
I write a strange Alloy demo about "assert" out of curiosity.
Assume there is a "Program", the "Program" has 2 "Varieties", and each "Variety" has a "Value" from "Data" set.
Then I also set a "fact" that all of the "Value" of the "Variety" are "data1".
Finally, I set an "assert" that for all "Program", all of "Value" of the "Variety" in the "Program" are "data1".
I think the "assert" satisfies the "fact", however when I check the "assert", it gives a counterexample, I cannot understand about this, why it has the counterexample?
The code appears as follows:
enum Data{data1,data2}
sig Program{
Var1:Variable,
Var2:Variable
}
sig Variable{
Value:Data
}
fact{
all v:Variable{
v.Value=data1
}
}
assert test{
all p:Program{
all v:(Program->Variable){
p.v.Value=data1
}
}
}
The counterexample is as follows:
I'm a bit confused about your example because the var1 and var2 fields don't seem to be used. But the reason you're getting a counterexample is probably because v can be empty, in which case p.v.Value evaluates to the empty relation, and data1 evaluates to a singleton, so they're not equal.
There are two mistakes in my question, I modify the code, and it is right now.
enum Data{data1,data2}
sig Program{
Var1:Variable,
Var2:Variable
}
sig Variable{
Value:Data
}
fact{
all p:Program{
//In theory, there should be "all v:(Program->Variable)", but Alloy does not support HOL.
//all v:(Program->Variable){
p.Var1.Value=data1
p.Var2.Value=data1
// }
}
}
assert test{
all p:Program{
p.Var1.Value=data1
p.Var2.Value=data2
// And here is another mistake, Var1 and Var2 is only the subset of "all v:(Program->Variable)"
// all v:(Program->Variable){
// p.v.Value=data1
// }
}
}
check test for 10 but 1 Program
I'm working on a DSL using groovy, and as i'm new to this language, i'm struggling on something.
i have this code
def from(state1) {
def closure
closure = { sensor ->
[becomes: { signal ->
// someProcess;
[and: closure]
}]
}
[to: { state2 ->
// someProcess
[when: closure]
}]
};
what i do is to read this kind of sentances
from "on" to "off" when "button" becomes "high" and "button2" becomes "high"
the and "button2" becomes "high", is optional. So grammatically, everything works as i wanted to.
the problem is that i wanted to add the possibility to treat or also, like this:
from "on" to "off" when "button" becomes "high" or "button2" becomes "high"
but i don't know how to do that. How can i do to add that, and also the possibility to know if it's and or or to have a control statement and a different process for each
it have been two days that i'm on the problem..
Thanks :)
1st of all, I like your question!
Not knowing what your //someProcess is supposed to do and what the whole use-case is all about (IoT-ish?), you can implement the or operator like that:
...
[to: { state2 ->
[when: closure, whenEither:{ Map conds -> conds.any{ sensor, signal -> 'high' == signal } } ]
}]
then you can write:
from "on" to "off" whenEither button:"high", button2:"high"
I'm using nightwatch to check that a table cell on a page contains a number greater than 0.
To achieve this I have to use the node assert package:
const assert = require('assert');
So first, I get the table cell element text, and in the callback I parse it to an int and use assert to check it's value:
...
.getText("//table[#id='topology-summary-table']/tbody/tr/td[7]", function(el){
assert(parseInt(el.value) > 0, "Num Executors == 0!");
}).end()
...
The only problem with this is that if assert throws an AssertionError (ie: if the number in the table cell is 0), then the test halts, and .end() never gets called, thus leaving the browser process open and hanging around. Not ideal.
I have got around that fact by doing the following:
...
.getText("//table[#id='topology-summary-table']/tbody/tr/td[7]", function(el){
try {
assert(parseInt(el.value) > 0, "Num Executors == 0!");
} catch(e){
this.end();
throw e;
}
})
...
but for some reasons this makes me feel bad. :(
My question is: Is there a better way?
The nightwatch api actually extends the assert api, so there is no need to require it.
Instead, do this:
.getText("//table[#id='topology-summary-table']/tbody/tr/td[7]", function(el){
this.assert.ok(parseInt(el.value) > 0, "Num Workers == 0!");
})
Answer provided by beatfactor here: https://github.com/nightwatchjs/nightwatch/issues/1002#issuecomment-223240103