(t *testing.T)
| 241 | } |
| 242 | |
| 243 | func TestMapMemory(t *testing.T) { |
| 244 | ctx := log.Testing(t) |
| 245 | for _, test := range []struct { |
| 246 | name string |
| 247 | f func(*Builder) |
| 248 | expected []asm.Instruction |
| 249 | }{ |
| 250 | { |
| 251 | "No mapping", |
| 252 | func(b *Builder) { |
| 253 | b.BeginCommand(10, 0) |
| 254 | b.Push(value.ObservedPointer(0x100004)) |
| 255 | b.Call(FunctionInfo{0, 123, protocol.Type_VolatilePointer, 1}) |
| 256 | b.CommitCommand() |
| 257 | }, |
| 258 | []asm.Instruction{ |
| 259 | asm.Label{Value: 10}, |
| 260 | asm.Push{Value: value.ObservedPointer(0x100004)}, |
| 261 | asm.Call{ApiIndex: 0, FunctionID: 123}, |
| 262 | }, |
| 263 | }, |
| 264 | { |
| 265 | "MapMemory", |
| 266 | func(b *Builder) { |
| 267 | b.BeginCommand(10, 0) |
| 268 | b.Call(FunctionInfo{0, 100, protocol.Type_AbsolutePointer, 0}) |
| 269 | b.MapMemory(memory.Range{Base: 0x100000, Size: 0x10}) |
| 270 | b.CommitCommand() |
| 271 | |
| 272 | b.BeginCommand(20, 0) |
| 273 | b.Push(value.ObservedPointer(0x100004)) |
| 274 | b.Call(FunctionInfo{0, 123, protocol.Type_Void, 1}) |
| 275 | b.CommitCommand() |
| 276 | }, |
| 277 | []asm.Instruction{ |
| 278 | asm.Label{Value: 10}, |
| 279 | asm.Call{ApiIndex: 0, FunctionID: 100, PushReturn: true}, |
| 280 | asm.Store{Destination: value.VolatilePointer(0x0)}, // mapping-storage address |
| 281 | |
| 282 | asm.Label{Value: 20}, |
| 283 | asm.Load{DataType: protocol.Type_AbsolutePointer, Source: value.VolatilePointer(0x0)}, // mapping-storage address |
| 284 | asm.Push{Value: value.AbsolutePointer(0x4)}, |
| 285 | asm.Add{Count: 2}, |
| 286 | asm.Call{ApiIndex: 0, FunctionID: 123}, |
| 287 | }, |
| 288 | }, |
| 289 | { |
| 290 | "UnmapMemory", |
| 291 | func(b *Builder) { |
| 292 | b.BeginCommand(10, 0) |
| 293 | b.Call(FunctionInfo{0, 100, protocol.Type_AbsolutePointer, 0}) |
| 294 | b.MapMemory(memory.Range{Base: 0x100000, Size: 0x10}) |
| 295 | b.CommitCommand() |
| 296 | |
| 297 | b.BeginCommand(20, 0) |
| 298 | b.UnmapMemory(memory.Range{Base: 0x100000, Size: 0x10}) |
| 299 | b.CommitCommand() |
| 300 |
nothing calls this directly
no test coverage detected