mirror of
https://github.com/taigrr/gopher-os
synced 2026-03-24 13:22:23 -07:00
acpi: tag entities with the handle of the table that defines them
This allows us to implement the Unload opcode which given a handle, removes all entities that are tagged by it.
This commit is contained in:
@@ -33,7 +33,7 @@ func TestParser(t *testing.T) {
|
||||
|
||||
for _, tableName := range spec {
|
||||
tableName := strings.Replace(tableName, ".aml", "", -1)
|
||||
if err := p.ParseAML(tableName, resolver.LookupTable(tableName)); err != nil {
|
||||
if err := p.ParseAML(0, tableName, resolver.LookupTable(tableName)); err != nil {
|
||||
t.Errorf("[spec %d] [%s]: %v", specIndex, tableName, err)
|
||||
break
|
||||
}
|
||||
@@ -41,6 +41,56 @@ func TestParser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTableHandleAssignment(t *testing.T) {
|
||||
var resolver = mockResolver{tableFiles: []string{"parser-testsuite-DSDT.aml"}}
|
||||
|
||||
// Create default scopes
|
||||
rootNS := &scopeEntity{op: opScope, name: `\`}
|
||||
rootNS.Append(&scopeEntity{op: opScope, name: `_GPE`}) // General events in GPE register block
|
||||
rootNS.Append(&scopeEntity{op: opScope, name: `_PR_`}) // ACPI 1.0 processor namespace
|
||||
rootNS.Append(&scopeEntity{op: opScope, name: `_SB_`}) // System bus with all device objects
|
||||
rootNS.Append(&scopeEntity{op: opScope, name: `_SI_`}) // System indicators
|
||||
rootNS.Append(&scopeEntity{op: opScope, name: `_TZ_`}) // ACPI 1.0 thermal zone namespace
|
||||
|
||||
p := NewParser(ioutil.Discard, rootNS)
|
||||
|
||||
expHandle := uint8(42)
|
||||
tableName := "parser-testsuite-DSDT"
|
||||
if err := p.ParseAML(expHandle, tableName, resolver.LookupTable(tableName)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// Drop all entities that were assigned the handle value
|
||||
var unloadList []Entity
|
||||
scopeVisit(0, p.root, EntityTypeAny, func(_ int, ent Entity) bool {
|
||||
if ent.TableHandle() == expHandle {
|
||||
unloadList = append(unloadList, ent)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
for _, ent := range unloadList {
|
||||
if p := ent.Parent(); p != nil {
|
||||
p.removeChild(ent)
|
||||
}
|
||||
}
|
||||
|
||||
// We should end up with the original tree
|
||||
var visitedNodes int
|
||||
scopeVisit(0, p.root, EntityTypeAny, func(_ int, ent Entity) bool {
|
||||
visitedNodes++
|
||||
if ent.TableHandle() == expHandle {
|
||||
t.Errorf("encounted entity that should have been pruned: %#+v", ent)
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if exp := len(rootNS.Children()) + 1; visitedNodes != exp {
|
||||
t.Errorf("expected to visit %d nodes; visited %d", exp, visitedNodes)
|
||||
}
|
||||
}
|
||||
|
||||
func pkgDir() string {
|
||||
_, f, _, _ := runtime.Caller(1)
|
||||
return filepath.Dir(f)
|
||||
|
||||
Reference in New Issue
Block a user