Tests: validate::size grows its own stack; no owned contract list; written-by-ts.cc
This commit is contained in:
parent
b9920b20cd
commit
927085b7b5
3 changed files with 60 additions and 0 deletions
|
|
@ -994,6 +994,37 @@ fn the_stack_bound_counts_a_slot_argument() {
|
|||
stack_bound_counts(Through::SlotArgument);
|
||||
}
|
||||
|
||||
/// Runs `work` with only about `left` bytes of stack remaining: the stack is burned first, so a
|
||||
/// recursion that does not grow its own stack runs out inside it.
|
||||
#[inline(never)]
|
||||
fn with_stack_left(left: usize, work: &mut dyn FnMut()) {
|
||||
let remaining = stacker::remaining_stack().expect("the thread's stack limit is known");
|
||||
if remaining > left {
|
||||
let burn = [0u8; 4096];
|
||||
std::hint::black_box(&burn);
|
||||
with_stack_left(left, work);
|
||||
std::hint::black_box(&burn);
|
||||
} else {
|
||||
work();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn counting_a_deep_slot_argument_grows_its_own_stack() {
|
||||
// The body places a 900-level slot argument; the node limit refuses it where it is counted
|
||||
// (validate::size, a recursion over the argument), before anything clones it. Run with little
|
||||
// stack left, the count must move to a fresh segment to finish.
|
||||
let limits = limited(1500);
|
||||
let body = composition("c", &[("body", ParamKind::Slot)], boxed("b", vec![slot("body")]));
|
||||
let state = state_with(&[body]);
|
||||
let document = surface(boxed("root", vec![use_of("u", "c", vec![slot_arg("body", vec![chain(900, false)])])]), &[]);
|
||||
let mut resolution = None;
|
||||
with_stack_left(600 * 1024, &mut || resolution = Some(resolve(&document, &state, &limits)));
|
||||
let resolution = resolution.unwrap();
|
||||
refused_for_limit(&resolution);
|
||||
assert!(!too_deep_to_resolve(&resolution), "{:?}", resolution.diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_slot_naming_a_param_of_another_kind_is_invalid() {
|
||||
let body = composition("c", &[("x", ParamKind::Text)], boxed("b", vec![slot("x")]));
|
||||
|
|
|
|||
|
|
@ -38,6 +38,35 @@ public sealed class ReadOnlyListTests
|
|||
Assert.That(checkedProperties, Is.GreaterThan(200));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CultLib's element-id walk owns the elements of a list held as a class or interface of
|
||||
/// [MessagePackObject] or [Union] elements, and demands an id on each. A list held as an ImmutableArray is one
|
||||
/// whole value the walk never enters, so the contract holds every list that way.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void NoKeyMemberIsAnOwnedListOfContractObjects()
|
||||
{
|
||||
bool IsContractObject(Type type) =>
|
||||
type.GetCustomAttribute<MessagePackObjectAttribute>() != null || type.GetCustomAttributes<UnionAttribute>(false).Any();
|
||||
var offenders = new List<string>();
|
||||
var checkedMembers = 0;
|
||||
foreach (var type in typeof(CommandResult).Assembly.GetExportedTypes())
|
||||
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
if (property.GetCustomAttribute<KeyAttribute>() is null) continue;
|
||||
checkedMembers++;
|
||||
var t = property.PropertyType;
|
||||
if (t.IsValueType) continue;
|
||||
var element = t.GetInterfaces().Concat(new[] { t })
|
||||
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>))
|
||||
.Select(i => i.GetGenericArguments()[0]).FirstOrDefault();
|
||||
if (element != null && IsContractObject(element)) offenders.Add($"{type.Name}.{property.Name}: {t.Name}");
|
||||
}
|
||||
|
||||
Assert.That(offenders, Is.Empty);
|
||||
Assert.That(checkedMembers, Is.GreaterThan(100));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryListParameterIsCopiedAndTheCopyCannotGrow()
|
||||
{
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue