gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/state/tests/load.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tests 16 17 import "context" 18 19 // +stateify savable 20 type genericContainer struct { 21 v any 22 } 23 24 // +stateify savable 25 type afterLoadStruct struct { 26 v int `state:"nosave"` 27 } 28 29 func (a *afterLoadStruct) afterLoad(context.Context) { 30 a.v++ 31 } 32 33 // +stateify savable 34 type valueLoadStruct struct { 35 v int `state:".(int64)"` 36 } 37 38 func (v *valueLoadStruct) saveV() int64 { 39 return int64(v.v) // Save as int64. 40 } 41 42 func (v *valueLoadStruct) loadV(_ context.Context, value int64) { 43 v.v = int(value) // Load as int. 44 } 45 46 // +stateify savable 47 type cycleStruct struct { 48 c *cycleStruct 49 } 50 51 // +stateify savable 52 type badCycleStruct struct { 53 b *badCycleStruct `state:"wait"` 54 } 55 56 func (b *badCycleStruct) afterLoad(context.Context) { 57 if b.b != b { 58 // This is not executable, since AfterLoad requires that the 59 // object and all dependencies are complete. This should cause 60 // a deadlock error during load. 61 panic("badCycleStruct.afterLoad called") 62 } 63 }