Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
FolderOrigin-RevId: /usr/local/google/home/gdennis/copybara/temp/folder-destination6564563148476583398/.
  • Loading branch information
GGN Engprod Team authored and greg-dennis committed Jan 17, 2023
1 parent 8e19d8c commit 3b28896
Show file tree
Hide file tree
Showing 61 changed files with 44,576 additions and 44,136 deletions.
10 changes: 10 additions & 0 deletions binding/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (d *AbstractDUT) Ports() map[string]*Port {
return d.Dims.Ports
}

// CustomData returns custom data for the DUT.
func (d *AbstractDUT) CustomData() map[string]any {
return d.Dims.CustomData
}

func (d *AbstractDUT) String() string {
return fmt.Sprintf("DUT%+v", *d)
}
Expand Down Expand Up @@ -153,6 +158,11 @@ func (a *AbstractATE) Ports() map[string]*Port {
return a.Dims.Ports
}

// CustomData returns custom data for the ATE.
func (a *AbstractATE) CustomData() map[string]any {
return a.Dims.CustomData
}

func (a *AbstractATE) String() string {
return fmt.Sprintf("ATE%+v", *a)
}
Expand Down
2 changes: 2 additions & 0 deletions binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Device interface {
HardwareModel() string
SoftwareVersion() string
Ports() map[string]*Port
CustomData() map[string]any
}

// Dims contains the dimensions of reserved DUT or ATE.
Expand All @@ -110,6 +111,7 @@ type Dims struct {
HardwareModel string
SoftwareVersion string
Ports map[string]*Port
CustomData map[string]any
}

func (d *Dims) String() string {
Expand Down
2 changes: 1 addition & 1 deletion binding/grpcutil/testservice/gen/testservice.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 69 additions & 61 deletions binding/portgraph/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type LeafPortConstraint interface {
PortConstraint
}

// LeafConstraint is a constraint checker that checks an input matches based on some matching criteria.
// LeafConstraint is a constraint checker that checks the input matches based on some matching criteria.
type LeafConstraint interface {
universalLeafConstraint
match(string, bool) bool
Expand All @@ -55,118 +55,126 @@ type universalLeafConstraint interface {

type equal struct {
universalLeafConstraint
s string
s string
not bool
}

func (c *equal) match(s string, ok bool) bool {
if c.not {
return ok && s != c.s
}
return ok && s == c.s
}

type notEqual struct {
universalLeafConstraint
s string
}

func (c *notEqual) match(s string, ok bool) bool {
return ok && s != c.s
}

type regex struct {
universalLeafConstraint
re *regexp.Regexp
re *regexp.Regexp
not bool
}

func (c *regex) match(s string, ok bool) bool {
if c.not {
return ok && !c.re.MatchString(s)
}
return ok && c.re.MatchString(s)
}

type notRegex struct {
universalLeafConstraint
re *regexp.Regexp
}

func (c *notRegex) match(s string, ok bool) bool {
return ok && !c.re.MatchString(s)
}

func attrsNodePair(k string, n1, n2 *AbstractNode, abs2ConNode map[*AbstractNode]*ConcreteNode) (string, string, bool) {
cn1, ok := abs2ConNode[n1]
v1, ok := attrNode(k, n1, abs2ConNode)
if !ok {
log.Fatalf("node %q does not have an assignment", n1.Desc)
return "", "", false
}
v1, ok := cn1.Attrs[k]
v2, ok := attrNode(k, n2, abs2ConNode)
if !ok {
return "", "", false
}
cn2, ok := abs2ConNode[n2]
return v1, v2, ok
}

func attrNode(k string, n *AbstractNode, abs2ConNode map[*AbstractNode]*ConcreteNode) (string, bool) {
cn, ok := abs2ConNode[n]
if !ok {
log.Fatalf("node %q does not have an assignment", n2.Desc)
log.Fatalf("node %q does not have an assignment", n.Desc)
}
v2, ok := cn2.Attrs[k]
v, ok := cn.Attrs[k]
if !ok {
return "", "", false
return "", false
}
return v1, v2, ok
return v, ok
}

func attrsPortPair(k string, p1, p2 *AbstractPort, abs2ConPort map[*AbstractPort]*ConcretePort) (string, string, bool) {
cp1, ok := abs2ConPort[p1]
v1, ok := attrPort(k, p1, abs2ConPort)
if !ok {
log.Fatalf("port %q does not have an assignement", p1.Desc)
return "", "", false
}
v1, ok := cp1.Attrs[k]
v2, ok := attrPort(k, p2, abs2ConPort)
if !ok {
return "", "", false
}
cp2, ok := abs2ConPort[p2]
return v1, v2, ok
}

func attrPort(k string, p *AbstractPort, abs2ConPort map[*AbstractPort]*ConcretePort) (string, bool) {
cp, ok := abs2ConPort[p]
if !ok {
log.Fatalf("port %q does not have an assignment", p2.Desc)
log.Fatalf("port %q does not have an assignment", p.Desc)
}
v2, ok := cp2.Attrs[k]
v, ok := cp.Attrs[k]
if !ok {
return "", "", false
return "", false
}
return v1, v2, ok
return v, ok
}

type sameAsNode struct {
LeafNodeConstraint
n *AbstractNode
n *AbstractNode
not bool
}

func (c *sameAsNode) match(k string, n *AbstractNode, abs2ConNode map[*AbstractNode]*ConcreteNode) bool {
v1, v2, ok := attrsNodePair(k, n, c.n, abs2ConNode)
if c.not {
return ok && v1 != v2
}
return ok && v1 == v2
}

func (c *sameAsNode) evaluate(k string, abs2ConNode map[*AbstractNode]*ConcreteNode) LeafConstraint {
v, ok := attrNode(k, c.n, abs2ConNode)
if !ok {
return nil
}
return &equal{
s: v,
not: c.not,
}
}

type sameAsPort struct {
LeafPortConstraint
p *AbstractPort
p *AbstractPort
not bool
}

func (c *sameAsPort) match(k string, p *AbstractPort, abs2ConPort map[*AbstractPort]*ConcretePort) bool {
v1, v2, ok := attrsPortPair(k, p, c.p, abs2ConPort)
if c.not {
return ok && v1 != v2
}
return ok && v1 == v2
}

type notSameAsNode struct {
LeafNodeConstraint
n *AbstractNode
}

func (c *notSameAsNode) match(k string, n *AbstractNode, abs2ConNode map[*AbstractNode]*ConcreteNode) bool {
v1, v2, ok := attrsNodePair(k, n, c.n, abs2ConNode)
return ok && v1 != v2
}

type notSameAsPort struct {
LeafPortConstraint
p *AbstractPort
}

func (c *notSameAsPort) match(k string, p *AbstractPort, abs2ConPort map[*AbstractPort]*ConcretePort) bool {
v1, v2, ok := attrsPortPair(k, p, c.p, abs2ConPort)
return ok && v1 != v2
func (c *sameAsPort) evaluate(k string, abs2ConPort map[*AbstractPort]*ConcretePort) LeafConstraint {
v, ok := attrPort(k, c.p, abs2ConPort)
if !ok {
return nil
}
return &equal{
s: v,
not: c.not,
}
}

type andNode struct {
Expand Down Expand Up @@ -198,7 +206,7 @@ func Equal(s string) LeafConstraint {

// NotEqual returns a constraint that an attribute is not equal to the specified string.
func NotEqual(s string) LeafConstraint {
return &notEqual{s: s}
return &equal{s: s, not: true}
}

// Regex returns a constraint that an attribute matches the specified regex.
Expand All @@ -208,7 +216,7 @@ func Regex(re *regexp.Regexp) LeafConstraint {

// NotRegex returns a constraint that an attribute does not match the specified regex.
func NotRegex(re *regexp.Regexp) LeafConstraint {
return &notRegex{re: re}
return &regex{re: re, not: true}
}

// SameAsNode returns a constraint that an attribute has the same value as the specified Node.
Expand All @@ -218,7 +226,7 @@ func SameAsNode(n *AbstractNode) LeafNodeConstraint {

// NotSameAsNode returns a constraint that an attribute has a different value from the specified Node.
func NotSameAsNode(n *AbstractNode) LeafNodeConstraint {
return &notSameAsNode{n: n}
return &sameAsNode{n: n, not: true}
}

// SameAsPort returns a constraint that an attribute has the same value as the specified Port.
Expand All @@ -228,5 +236,5 @@ func SameAsPort(p *AbstractPort) LeafPortConstraint {

// NotSameAsPort returns a constraint that an attribute has a different value from the specified Port.
func NotSameAsPort(p *AbstractPort) LeafPortConstraint {
return &notSameAsPort{p: p}
return &sameAsPort{p: p, not: true}
}
Loading

0 comments on commit 3b28896

Please sign in to comment.