text:
}
	require.NoError(t, err)

	amd64 := platforms.MustParse("linux/amd64")
	arm64 := platforms.MustParse("linux/arm64")
	ps := []ocispecs.Platform{amd64, arm64}

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()
		expPlatforms := &exptypes.Platforms{
			Platforms: make([]exptypes.Platform, len(ps)),
		}
		for i, p := range ps {
			st := llb.Scratch().File(
				llb.Mkfile("platform", 0600, []byte(platforms.Format(p))),
			)

			def, err := st.Marshal(ctx)
			if err != nil {
				return nil, err
			}

			r, err := c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}

			ref, err := r.SingleRef()
			if err != nil {
				return nil, err
			}

			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}

			k := platforms.Format(p)
			res.AddRef(k, ref)

			expPlatforms.Platforms[i] = exptypes.Platform{
				ID:       k,
				Platform: p,
			}
		}
		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		res.AddMeta(exptypes.AnnotationIndexKey("gi"), []byte("generic index"))
		res.AddMeta(exptypes.AnnotationIndexDescriptorKey("gid"), []byte("generic index descriptor"))
		res.AddMeta(exptypes.AnnotationManifestKey(nil, "gm"), []byte("generic manifest"))
		res.AddMeta(exptypes.AnnotationManifestDescriptorKey(nil, "gmd"), []byte("generic manifest descriptor"))
		res.AddMeta(exptypes.AnnotationManifestKey(&amd64, "m"), []byte("amd64 manifest"))
		res.AddMeta(exptypes.AnnotationManifestKey(&arm64, "m"), []byte("arm64 manifest"))
		res.AddMeta(exptypes.AnnotationManifestDescriptorKey(&amd64, "md"), []byte("amd64 manifest descriptor"))
		res.AddMeta(exptypes.AnnotationManifestDescriptorKey(&arm64, "md"), []byte("arm64 manifest descriptor"))
		res.AddMeta(exptypes.AnnotationKey{Key: "gd"}.String(), []byte("generic default"))

		return res, nil
	}

	// testing for image exporter

	target := registry + "/buildkit/testannotations:latest"

	const created = "2022-01-23T12:34:56Z"

	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name":                 target,
					"push":                 "true",
					"annotation-index.gio": "generic index opt",
					"annotation-index." + ocispecs.AnnotationCreated:  created,
					"annotation-manifest.gmo":                         "generic manifest opt",
					"annotation-manifest-descriptor.gmdo":             "generic manifest descriptor opt",
					"annotation-manifest[linux/amd64].mo":             "amd64 manifest opt",
					"annotation-manifest-descriptor[linux/amd64].mdo": "amd64 manifest descriptor opt",
					"annotation-manifest[linux/arm64].mo":             "arm64 manifest opt",
					"annotation-manifest-descriptor[linux/arm64].mdo": "arm64 manifest descriptor opt",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)
	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	require.Equal(t, "generic index", imgs.Index.Annotations["gi"])
	require.Equal(t, "generic index opt", imgs.Index.Annotations["gio"])
	require.Equal(t, created, imgs.Index.Annotations[ocispecs.AnnotationCreated])
	for _, desc := range imgs.Index.Manifests {
		require.Equal(t, "generic manifest descriptor", desc.Annotations["gmd"])
		require.Equal(t, "generic manifest descriptor opt", desc.Annotations["gmdo"])
		switch {
		case platforms.Only(amd64).Match(*desc.Platform):
			require.Equal(t, "amd64 manifest descriptor", desc.Annotations["md"])
			require.Equal(t, "amd64 manifest descriptor opt", desc.Annotations["mdo"])
		case platforms.Only(arm64).Match(*desc.Platform):
			require.Equal(t, "arm64 manifest descriptor", desc.Annotations["md"])
			require.Equal(t, "arm64 manifest descriptor opt", desc.Annotations["mdo"])
		default:
			require.Fail(t, "unrecognized platform")
		}
	}

	amdImage := imgs.Find(platforms.Format(amd64))
	require.Equal(t, "generic default", amdImage.Manifest.Annotations["gd"])
	require.Equal(t, "generic manifest", amdImage.Manifest.Annotations["gm"])
	require.Equal(t, "generic manifest opt", amdImage.Manifest.Annotations["gmo"])
	require.Equal(t, "amd64 manifest", amdImage.Manifest.Annotations["m"])
	require.Equal(t, "amd64 manifest opt", amdImage.Manifest.Annotations["mo"])

	armImage := imgs.Find(platforms.Format(arm64))
	require.Equal(t, "generic default", armImage.Manifest.Annotations["gd"])
	require.Equal(t, "generic manifest", armImage.Manifest.Annotations["gm"])
	require.Equal(t, "generic manifest opt", armImage.Manifest.Annotations["gmo"])
	require.Equal(t, "arm64 manifest", armImage.Manifest.Annotations["m"])
	require.Equal(t, "arm64 manifest opt", armImage.Manifest.Annotations["mo"])

	// testing for oci exporter

	destDir := t.TempDir()

	out := filepath.Join(destDir, "out.tar")
	outW, err := os.Create(out)
	require.NoError(t, err)

	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type:   ExporterOCI,
				Output: fixedWriteCloser(outW),
				Attrs: map[string]string{
					"annotation-index.gio":                                      "generic index opt",
					"annotation-index-descriptor.gido":                          "generic index descriptor opt",
					"annotation-index-descriptor." + ocispecs.AnnotationCreated: created,
					"annotation-manifest.gmo":                                   "generic manifest opt",
					"annotation-manifest-descriptor.gmdo":                       "generic manifest descriptor opt",
					"annotation-manifest[linux/amd64].mo":                       "amd64 manifest opt",
					"annotation-manifest-descriptor[linux/amd64].mdo":           "amd64 manifest descriptor opt",
					"annotation-manifest[linux/arm64].mo":                       "arm64 manifest opt",
					"annotation-manifest-descriptor[linux/arm64].mdo":           "arm64 manifest descriptor opt",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	dt, err := os.ReadFile(out)
	require.NoError(t, err)

	m, err := testutil.ReadTarToMap(dt, false)
	require.NoError(t, err)

	var layout ocispecs.Index
	err = json.Unmarshal(m["index.json"].Data, &layout)
	require.Equal(t, "generic index descriptor", layout.Manifests[0].Annotations["gid"])
	require.Equal(t, "generic index descriptor opt", layout.Manifests[0].Annotations["gido"])
	require.Equal(t, created, layout.Manifests[0].Annotations[ocispecs.AnnotationCreated])
	require.NoError(t, err)

	var index ocispecs.Index
	err = json.Unmarshal(m["blobs/sha256/"+layout.Manifests[0].Digest.Hex()].Data, &index)
	require.Equal(t, "generic index", index.Annotations["gi"])
	require.Equal(t, "generic index opt", index.Annotations["gio"])
	require.NoError(t, err)

	for _, desc := range index.Manifests {
		var mfst ocispecs.Manifest
		err = json.Unmarshal(m["blobs/sha256/"+desc.Digest.Hex()].Data, &mfst)
		require.NoError(t, err)

		require.Equal(t, "generic default", mfst.Annotations["gd"])
		require.Equal(t, "generic manifest", mfst.Annotations["gm"])
		require.Equal(t, "generic manifest descriptor", desc.Annotations["gmd"])
		require.Equal(t, "generic manifest opt", mfst.Annotations["gmo"])
		require.Equal(t, "generic manifest descriptor opt", desc.Annotations["gmdo"])

		switch {
		case platforms.Only(amd64).Match(*desc.Platform):
			require.Equal(t, "amd64 manifest", mfst.Annotations["m"])
			require.Equal(t, "amd64 manifest descriptor", desc.Annotations["md"])
			require.Equal(t, "amd64 manifest opt", mfst.Annotations["mo"])
			require.Equal(t, "amd64 manifest descriptor opt", desc.Annotations["mdo"])
		case platforms.Only(arm64).Match(*desc.Platform):
			require.Equal(t, "arm64 manifest", mfst.Annotations["m"])
			require.Equal(t, "arm64 manifest descriptor", desc.Annotations["md"])
			require.Equal(t, "arm64 manifest opt", mfst.Annotations["mo"])
			require.Equal(t, "arm64 manifest descriptor opt", desc.Annotations["mdo"])
		default:
			require.Fail(t, "unrecognized platform")
		}
	}
}

func testExportAnnotationsMediaTypes(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	p := platforms.DefaultSpec()
	ps := []ocispecs.Platform{p}

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()
		expPlatforms := &exptypes.Platforms{
			Platforms: make([]exptypes.Platform, len(ps)),
		}
		for i, p := range ps {
			st := llb.Scratch().File(
				llb.Mkfile("platform", 0600, []byte(platforms.Format(p))),
			)

			def, err := st.Marshal(ctx)
			if err != nil {
				return nil, err
			}

			r, err := c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}

			ref, err := r.SingleRef()
			if err != nil {
				return nil, err
			}

			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}

			k := platforms.Format(p)
			res.AddRef(k, ref)

			expPlatforms.Platforms[i] = exptypes.Platform{
				ID:       k,
				Platform: p,
			}
		}
		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		return res, nil
	}

	target := registry + "/buildkit/testannotationsmedia:1"
	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name":                  target,
					"push":                  "true",
					"annotation-manifest.a": "b",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)
	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 1, len(imgs.Images))

	target2 := registry + "/buildkit/testannotationsmedia:2"
	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name":               target2,
					"push":               "true",
					"annotation-index.c": "d",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	desc, provider, err = contentutil.ProviderFromRef(target2)
	require.NoError(t, err)
	imgs2, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 1, len(imgs2.Images))

	require.Equal(t, "b", imgs.Images[0].Manifest.Annotations["a"])
	require.Equal(t, "d", imgs2.Index.Annotations["c"])

	require.Equal(t, images.MediaTypeDockerSchema2ManifestList, imgs.Index.MediaType)
	require.Equal(t, ocispecs.MediaTypeImageIndex, imgs2.Index.MediaType)
}

func testExportAttestations(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	ps := []ocispecs.Platform{
		platforms.MustParse("linux/amd64"),
		platforms.MustParse("linux/arm64"),
	}

	success := []byte(`{"success": true}`)
	successDigest := digest.SHA256.FromBytes(success)

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()
		expPlatforms := &exptypes.Platforms{}

		for _, p := range ps {
			pk := platforms.Format(p)
			expPlatforms.Platforms = append(expPlatforms.Platforms, exptypes.Platform{ID: pk, Platform: p})

			// build image
			st := llb.Scratch().File(
				llb.Mkfile("/greeting", 0600, []byte(fmt.Sprintf("hello %s!", pk))),
			)
			def, err := st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err := c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			ref, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddRef(pk, ref)

			// build attestations
			st = llb.Scratch().
				File(llb.Mkfile("/attestation.json", 0600, success)).
				File(llb.Mkfile("/attestation2.json", 0600, []byte{}))
			def, err = st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err = c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			refAttest, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddAttestation(pk, gateway.Attestation{
				Kind: gatewaypb.AttestationKindInToto,
				Ref:  refAttest,
				Path: "/attestation.json",
				InToto: result.InTotoAttestation{
					PredicateType: "https://example.com/attestations/v1.0",
					Subjects: []result.InTotoSubject{{
						Kind: gatewaypb.InTotoSubjectKindSelf,
					}},
				},
			})
			res.AddAttestation(pk, gateway.Attestation{
				Kind: gatewaypb.AttestationKindInToto,
				Ref:  refAttest,
				Path: "/attestation2.json",
				InToto: result.InTotoAttestation{
					PredicateType: "https://example.com/attestations2/v1.0",
					Subjects: []result.InTotoSubject{{
						Kind:   gatewaypb.InTotoSubjectKindRaw,
						Name:   "/attestation.json",
						Digest: []digest.Digest{successDigest},
					}},
				},
			})
		}

		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		return res, nil
	}

	t.Run("image", func(t *testing.T) {
		targets := []string{
			registry + "/buildkit/testattestationsfoo:latest",
			registry + "/buildkit/testattestationsbar:latest",
		}
		_, err = c.Build(sb.Context(), SolveOpt{
			Exports: []ExportEntry{
				{
					Type: ExporterImage,
					Attrs: map[string]string{
						"name": strings.Join(targets, ","),
						"push": "true",
					},
				},
			},
		}, "", frontend, nil)
		require.NoError(t, err)

		desc, provider, err := contentutil.ProviderFromRef(targets[0])
		require.NoError(t, err)

		imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
		require.NoError(t, err)
		require.Equal(t, len(ps)*2, len(imgs.Images))

		var bases []*testutil.ImageInfo
		for _, p := range ps {
			pk := platforms.Format(p)
			img := imgs.Find(pk)
			require.NotNil(t, img)
			require.Equal(t, pk, platforms.Format(*img.Desc.Platform))
			require.Equal(t, 1, len(img.Layers))
			require.Equal(t, []byte(fmt.Sprintf("hello %s!", pk)), img.Layers[0]["greeting"].Data)
			bases = append(bases, img)
		}

		atts := imgs.Filter("unknown/unknown")
		require.Equal(t, len(ps), len(atts.Images))
		for i, att := range atts.Images {
			require.Equal(t, ocispecs.MediaTypeImageManifest, att.Desc.MediaType)
			require.Equal(t, "unknown/unknown", platforms.Format(*att.Desc.Platform))
			require.Equal(t, "unknown/unknown", att.Img.OS+"/"+att.Img.Architecture)
			require.Equal(t, attestation.DockerAnnotationReferenceTypeDefault, att.Desc.Annotations[attestation.DockerAnnotationReferenceType])
			require.Equal(t, bases[i].Desc.Digest.String(), att.Desc.Annotations[attestation.DockerAnnotationReferenceDigest])
			require.Equal(t, 2, len(att.Layers))
			require.Equal(t, len(att.Layers), len(att.Img.RootFS.DiffIDs))
			require.Equal(t, len(att.Img.History), 0)

			var attest intoto.Statement
			require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))

			purls := map[string]string{}
			for _, k := range targets {
				named, err := reference.ParseNormalizedNamed(k)
				require.NoError(t, err)
				name := reference.FamiliarName(named)
				version := ""
				if tagged, ok := named.(reference.Tagged); ok {
					version = tagged.Tag()
				}
				p := fmt.Sprintf("pkg:docker/%s%s@%s?platform=%s", url.QueryEscape(registry), strings.TrimPrefix(name, registry), version, url.PathEscape(platforms.Format(ps[i])))
				purls[k] = p
			}

			require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
			require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
			require.Equal(t, map[string]interface{}{"success": true}, attest.Predicate)
			subjects := []intoto.Subject{
				{
					Name: purls[targets[0]],
					Digest: map[string]string{
						"sha256": bases[i].Desc.Digest.Encoded(),
					},
				},
				{
					Name: purls[targets[1]],
					Digest: map[string]string{
						"sha256": bases[i].Desc.Digest.Encoded(),
					},
				},
			}
			require.Equal(t, subjects, attest.Subject)

			var attest2 intoto.Statement
			require.NoError(t, json.Unmarshal(att.LayersRaw[1], &attest2))

			require.Equal(t, "https://in-toto.io/Statement/v0.1", attest2.Type)
			require.Equal(t, "https://example.com/attestations2/v1.0", attest2.PredicateType)
			require.Nil(t, attest2.Predicate)
			subjects = []intoto.Subject{{
				Name: "/attestation.json",
				Digest: map[string]string{
					"sha256": successDigest.Encoded(),
				},
			}}
			require.Equal(t, subjects, attest2.Subject)
		}

		cdAddress := sb.ContainerdAddress()
		if cdAddress == "" {
			return
		}
		client, err := containerd.New(cdAddress)
		require.NoError(t, err)
		defer client.Close()
		ctx := namespaces.WithNamespace(sb.Context(), "buildkit")

		for _, target := range targets {
			err = client.ImageService().Delete(ctx, target, images.SynchronousDelete())
			require.NoError(t, err)
		}
		checkAllReleasable(t, c, sb, true)
	})

	t.Run("local", func(t *testing.T) {
		dir := t.TempDir()
		_, err = c.Build(sb.Context(), SolveOpt{
			Exports: []ExportEntry{
				{
					Type:      ExporterLocal,
					OutputDir: dir,
					Attrs: map[string]string{
						"attestation-prefix": "test.",
					},
				},
			},
		}, "", frontend, nil)
		require.NoError(t, err)

		for _, p := range ps {
			var attest intoto.Statement
			dt, err := os.ReadFile(path.Join(dir, strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json"))
			require.NoError(t, err)
			require.NoError(t, json.Unmarshal(dt, &attest))

			require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
			require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
			require.Equal(t, map[string]interface{}{"success": true}, attest.Predicate)

			require.Equal(t, []intoto.Subject{{
				Name:   "greeting",
				Digest: result.ToDigestMap(digest.Canonical.FromString("hello " + platforms.Format(p) + "!")),
			}}, attest.Subject)

			var attest2 intoto.Statement
			dt, err = os.ReadFile(path.Join(dir, strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json"))
			require.NoError(t, err)
			require.NoError(t, json.Unmarshal(dt, &attest2))

			require.Equal(t, "https://in-toto.io/Statement/v0.1", attest2.Type)
			require.Equal(t, "https://example.com/attestations2/v1.0", attest2.PredicateType)
			require.Nil(t, attest2.Predicate)
			subjects := []intoto.Subject{{
				Name: "/attestation.json",
				Digest: map[string]string{
					"sha256": successDigest.Encoded(),
				},
			}}
			require.Equal(t, subjects, attest2.Subject)
		}
	})

	t.Run("tar", func(t *testing.T) {
		dir := t.TempDir()
		out := filepath.Join(dir, "out.tar")
		outW, err := os.Create(out)
		require.NoError(t, err)

		_, err = c.Build(sb.Context(), SolveOpt{
			Exports: []ExportEntry{
				{
					Type:   ExporterTar,
					Output: fixedWriteCloser(outW),
					Attrs: map[string]string{
						"attestation-prefix": "test.",
					},
				},
			},
		}, "", frontend, nil)
		require.NoError(t, err)

		dt, err := os.ReadFile(out)
		require.NoError(t, err)

		m, err := testutil.ReadTarToMap(dt, false)
		require.NoError(t, err)

		for _, p := range ps {
			var attest intoto.Statement
			item := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")]
			require.NotNil(t, item)
			require.NoError(t, json.Unmarshal(item.Data, &attest))

			require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
			require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
			require.Equal(t, map[string]interface{}{"success": true}, attest.Predicate)

			require.Equal(t, []intoto.Subject{{
				Name:   "greeting",
				Digest: result.ToDigestMap(digest.Canonical.FromString("hello " + platforms.Format(p) + "!")),
			}}, attest.Subject)

			var attest2 intoto.Statement
			item = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")]
			require.NotNil(t, item)
			require.NoError(t, json.Unmarshal(item.Data, &attest2))

			require.Equal(t, "https://in-toto.io/Statement/v0.1", attest2.Type)
			require.Equal(t, "https://example.com/attestations2/v1.0", attest2.PredicateType)
			require.Nil(t, attest2.Predicate)
			subjects := []intoto.Subject{{
				Name: "/attestation.json",
				Digest: map[string]string{
					"sha256": successDigest.Encoded(),
				},
			}}
			require.Equal(t, subjects, attest2.Subject)
		}
	})
}

func testAttestationDefaultSubject(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	ps := []ocispecs.Platform{
		platforms.MustParse("linux/amd64"),
	}

	success := []byte(`{"success": true}`)

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()
		expPlatforms := &exptypes.Platforms{}

		for _, p := range ps {
			pk := platforms.Format(p)
			expPlatforms.Platforms = append(expPlatforms.Platforms, exptypes.Platform{ID: pk, Platform: p})

			// build image
			st := llb.Scratch().File(
				llb.Mkfile("/greeting", 0600, []byte(fmt.Sprintf("hello %s!", pk))),
			)
			def, err := st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err := c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			ref, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddRef(pk, ref)

			// build attestations
			st = llb.Scratch().File(llb.Mkfile("/attestation.json", 0600, success))
			def, err = st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err = c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			refAttest, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddAttestation(pk, gateway.Attestation{
				Kind: gatewaypb.AttestationKindInToto,
				Ref:  refAttest,
				Path: "/attestation.json",
				InToto: result.InTotoAttestation{
					PredicateType: "https://example.com/attestations/v1.0",
				},
			})
		}

		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		return res, nil
	}

	target := registry + "/buildkit/testattestationsemptysubject:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, len(ps)*2, len(imgs.Images))

	var bases []*testutil.ImageInfo
	for _, p := range ps {
		pk := platforms.Format(p)
		bases = append(bases, imgs.Find(pk))
	}

	atts := imgs.Filter("unknown/unknown")
	require.Equal(t, len(ps), len(atts.Images))
	for i, att := range atts.Images {
		var attest intoto.Statement
		require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))

		require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
		require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
		require.Equal(t, map[string]interface{}{"success": true}, attest.Predicate)

		name := fmt.Sprintf("pkg:docker/%s/buildkit/testattestationsemptysubject@latest?platform=%s", url.QueryEscape(registry), url.QueryEscape(platforms.Format(ps[i])))
		subjects := []intoto.Subject{{
			Name: name,
			Digest: map[string]string{
				"sha256": bases[i].Desc.Digest.Encoded(),
			},
		}}
		require.Equal(t, subjects, attest.Subject)
	}
}

func testAttestationBundle(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	ps := []ocispecs.Platform{
		platforms.MustParse("linux/amd64"),
	}

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()
		expPlatforms := &exptypes.Platforms{}

		for _, p := range ps {
			pk := platforms.Format(p)
			expPlatforms.Platforms = append(expPlatforms.Platforms, exptypes.Platform{ID: pk, Platform: p})

			// build image
			st := llb.Scratch().File(
				llb.Mkfile("/greeting", 0600, []byte(fmt.Sprintf("hello %s!", pk))),
			)
			def, err := st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err := c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			ref, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddRef(pk, ref)

			stmt := intoto.Statement{
				StatementHeader: intoto.StatementHeader{
					Type:          intoto.StatementInTotoV01,
					PredicateType: "https://example.com/attestations/v1.0",
				},
				Predicate: map[string]interface{}{
					"foo": "1",
				},
			}
			buff := bytes.NewBuffer(nil)
			enc := json.NewEncoder(buff)
			require.NoError(t, enc.Encode(stmt))

			// build attestations
			st = llb.Scratch()
			st = st.File(
				llb.Mkdir("/bundle", 0700),
			)
			st = st.File(
				llb.Mkfile("/bundle/attestation.json", 0600, buff.Bytes()),
			)
			def, err = st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err = c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			refAttest, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddAttestation(pk, gateway.Attestation{
				Kind: gatewaypb.AttestationKindBundle,
				Ref:  refAttest,
				Path: "/bundle",
			})
		}

		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		return res, nil
	}

	target := registry + "/buildkit/testattestationsbundle:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, len(ps)*2, len(imgs.Images))

	var bases []*testutil.ImageInfo
	for _, p := range ps {
		pk := platforms.Format(p)
		bases = append(bases, imgs.Find(pk))
	}

	atts := imgs.Filter("unknown/unknown")
	require.Equal(t, len(ps)*1, len(atts.Images))
	for i, att := range atts.Images {
		require.Equal(t, 1, len(att.LayersRaw))
		var attest intoto.Statement
		require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))

		require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
		require.Equal(t, map[string]interface{}{"foo": "1"}, attest.Predicate)
		name := fmt.Sprintf("pkg:docker/%s/buildkit/testattestationsbundle@latest?platform=%s", url.QueryEscape(registry), url.QueryEscape(platforms.Format(ps[i])))
		subjects := []intoto.Subject{{
			Name: name,
			Digest: map[string]string{
				"sha256": bases[i].Desc.Digest.Encoded(),
			},
		}}
		require.Equal(t, subjects, attest.Subject)
	}
}

func testSBOMScan(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush, workers.FeatureSBOM)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	p := platforms.MustParse("linux/amd64")
	pk := platforms.Format(p)

	scannerFrontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()

		st := llb.Image("busybox")
		def, err := st.Marshal(sb.Context())
		require.NoError(t, err)

		r, err := c.Solve(ctx, gateway.SolveRequest{
			Definition: def.ToPB(),
		})
		if err != nil {
			return nil, err
		}
		ref, err := r.SingleRef()
		if err != nil {
			return nil, err
		}
		_, err = ref.ToState()
		if err != nil {
			return nil, err
		}
		res.AddRef(pk, ref)

		expPlatforms := &exptypes.Platforms{
			Platforms: []exptypes.Platform{{ID: pk, Platform: p}},
		}
		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		var img ocispecs.Image
		cmd := `
cat <<EOF > $BUILDKIT_SCAN_DESTINATION/spdx.json
{
  "_type": "https://in-toto.io/Statement/v0.1",
  "predicateType": "https://spdx.dev/Document",
  "predicate": {"name": "fallback"}
}
EOF
`
		img.Config.Cmd = []string{"/bin/sh", "-c", cmd}
		config, err := json.Marshal(img)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to marshal image config")
		}
		res.AddMeta(fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, pk), config)

		return res, nil
	}

	scannerTarget := registry + "/buildkit/testsbomscanner:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": scannerTarget,
					"push": "true",
				},
			},
		},
	}, "", scannerFrontend, nil)
	require.NoError(t, err)

	makeTargetFrontend := func(attest bool) func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		return func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
			res := gateway.NewResult()

			// build image
			st := llb.Scratch().File(
				llb.Mkfile("/greeting", 0600, []byte("hello world!")),
			)
			def, err := st.Marshal(ctx)
			if err != nil {
				return nil, err
			}
			r, err := c.Solve(ctx, gateway.SolveRequest{
				Definition: def.ToPB(),
			})
			if err != nil {
				return nil, err
			}
			ref, err := r.SingleRef()
			if err != nil {
				return nil, err
			}
			_, err = ref.ToState()
			if err != nil {
				return nil, err
			}
			res.AddRef(pk, ref)

			expPlatforms := &exptypes.Platforms{
				Platforms: []exptypes.Platform{{ID: pk, Platform: p}},
			}
			dt, err := json.Marshal(expPlatforms)
			if err != nil {
				return nil, err
			}
			res.AddMeta(exptypes.ExporterPlatformsKey, dt)

			// build attestations
			if attest {
				st = llb.Scratch().
					File(llb.Mkfile("/result.spdx", 0600, []byte(`{"name": "frontend"}`)))
				def, err = st.Marshal(ctx)
				if err != nil {
					return nil, err
				}
				r, err = c.Solve(ctx, gateway.SolveRequest{
					Definition: def.ToPB(),
				})
				if err != nil {
					return nil, err
				}
				refAttest, err := r.SingleRef()
				if err != nil {
					return nil, err
				}
				_, err = ref.ToState()
				if err != nil {
					return nil, err
				}

				res.AddAttestation(pk, gateway.Attestation{
					Kind: gatewaypb.AttestationKindInToto,
					Ref:  refAttest,
					Path: "/result.spdx",
					InToto: result.InTotoAttestation{
						PredicateType: intoto.PredicateSPDX,
					},
				})
			}

			return res, nil
		}
	}

	// test the default fallback scanner
	target := registry + "/buildkit/testsbom:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		FrontendAttrs: map[string]string{
			"attest:sbom": "",
		},
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", makeTargetFrontend(false), nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	// test the frontend builtin scanner
	target = registry + "/buildkit/testsbom2:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		FrontendAttrs: map[string]string{
			"attest:sbom": "",
		},
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", makeTargetFrontend(true), nil)
	require.NoError(t, err)

	desc, provider, err = contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err = testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	att := imgs.Find("unknown/unknown")
	attest := intoto.Statement{}
	require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))
	require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
	require.Equal(t, intoto.PredicateSPDX, attest.PredicateType)
	require.Subset(t, attest.Predicate, map[string]interface{}{"name": "frontend"})

	// test the specified fallback scanner
	target = registry + "/buildkit/testsbom3:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		FrontendAttrs: map[string]string{
			"attest:sbom": "generator=" + scannerTarget,
		},
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", makeTargetFrontend(false), nil)
	require.NoError(t, err)

	desc, provider, err = contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err = testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	att = imgs.Find("unknown/unknown")
	attest = intoto.Statement{}
	require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))
	require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
	require.Equal(t, intoto.PredicateSPDX, attest.PredicateType)
	require.Subset(t, attest.Predicate, map[string]interface{}{"name": "fallback"})

	// test the builtin frontend scanner and the specified fallback scanner together
	target = registry + "/buildkit/testsbom3:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		FrontendAttrs: map[string]string{
			"attest:sbom": "generator=" + scannerTarget,
		},
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", makeTargetFrontend(true), nil)
	require.NoError(t, err)

	desc, provider, err = contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err = testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	att = imgs.Find("unknown/unknown")
	attest = intoto.Statement{}
	require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))
	require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
	require.Equal(t, intoto.PredicateSPDX, attest.PredicateType)
	require.Subset(t, attest.Predicate, map[string]interface{}{"name": "frontend"})
}

func testSBOMScanSingleRef(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush, workers.FeatureSBOM)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	p := platforms.DefaultSpec()
	pk := platforms.Format(p)

	scannerFrontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()

		st := llb.Image("busybox")
		def, err := st.Marshal(sb.Context())
		require.NoError(t, err)

		r, err := c.Solve(ctx, gateway.SolveRequest{
			Definition: def.ToPB(),
		})
		if err != nil {
			return nil, err
		}
		ref, err := r.SingleRef()
		if err != nil {
			return nil, err
		}
		_, err = ref.ToState()
		if err != nil {
			return nil, err
		}
		res.AddRef(pk, ref)

		expPlatforms := &exptypes.Platforms{
			Platforms: []exptypes.Platform{{ID: pk, Platform: p}},
		}
		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		var img ocispecs.Image
		cmd := `
cat <<EOF > $BUILDKIT_SCAN_DESTINATION/spdx.json
{
  "_type": "https://in-toto.io/Statement/v0.1",
  "predicateType": "https://spdx.dev/Document",
  "predicate": {"name": "fallback"}
}
EOF
`
		img.Config.Cmd = []string{"/bin/sh", "-c", cmd}
		config, err := json.Marshal(img)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to marshal image config")
		}
		res.AddMeta(fmt.Sprintf("%s/%s", exptypes.ExporterImageConfigKey, pk), config)

		return res, nil
	}

	scannerTarget := registry + "/buildkit/testsbomscanner:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": scannerTarget,
					"push": "true",
				},
			},
		},
	}, "", scannerFrontend, nil)
	require.NoError(t, err)

	targetFrontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()

		// build image
		st := llb.Scratch().File(
			llb.Mkfile("/greeting", 0600, []byte("hello world!")),
		)
		def, err := st.Marshal(ctx)
		if err != nil {
			return nil, err
		}
		r, err := c.Solve(ctx, gateway.SolveRequest{
			Definition: def.ToPB(),
		})
		if err != nil {
			return nil, err
		}
		ref, err := r.SingleRef()
		if err != nil {
			return nil, err
		}
		_, err = ref.ToState()
		if err != nil {
			return nil, err
		}
		res.SetRef(ref)

		var img ocispecs.Image
		img.Config.Cmd = []string{"/bin/sh", "-c", "cat /greeting"}
		config, err := json.Marshal(img)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to marshal image config")
		}
		res.AddMeta(exptypes.ExporterImageConfigKey, config)

		expPlatforms := &exptypes.Platforms{
			Platforms: []exptypes.Platform{{ID: pk, Platform: p}},
		}
		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		return res, nil
	}

	target := registry + "/buildkit/testsbomsingle:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		FrontendAttrs: map[string]string{
			"attest:sbom": "generator=" + scannerTarget,
		},
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", targetFrontend, nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	img := imgs.Find(pk)
	require.NotNil(t, img)
	require.Equal(t, []string{"/bin/sh", "-c", "cat /greeting"}, img.Img.Config.Cmd)

	att := imgs.Find("unknown/unknown")
	require.NotNil(t, att)
	attest := intoto.Statement{}
	require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))
	require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
	require.Equal(t, intoto.PredicateSPDX, attest.PredicateType)
	require.Subset(t, attest.Predicate, map[string]interface{}{"name": "fallback"})
}

func testSBOMSupplements(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush, workers.FeatureSBOM)
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	p := platforms.MustParse("linux/amd64")
	pk := platforms.Format(p)

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		res := gateway.NewResult()

		// build image
		st := llb.Scratch().File(
			llb.Mkfile("/foo", 0600, []byte{}),
		)
		def, err := st.Marshal(ctx)
		if err != nil {
			return nil, err
		}
		r, err := c.Solve(ctx, gateway.SolveRequest{
			Definition: def.ToPB(),
		})
		if err != nil {
			return nil, err
		}
		ref, err := r.SingleRef()
		if err != nil {
			return nil, err
		}
		_, err = ref.ToState()
		if err != nil {
			return nil, err
		}
		res.AddRef(pk, ref)

		expPlatforms := &exptypes.Platforms{
			Platforms: []exptypes.Platform{{ID: pk, Platform: p}},
		}
		dt, err := json.Marshal(expPlatforms)
		if err != nil {
			return nil, err
		}
		res.AddMeta(exptypes.ExporterPlatformsKey, dt)

		// build attestations
		doc := spdx.Document{
			SPDXVersion:    "SPDX-2.2",
			SPDXIdentifier: "DOCUMENT",
			Files: []*spdx.File{
				{
					// foo exists...
					FileSPDXIdentifier: "SPDXRef-File-foo",
					FileName:           "/foo",
				},
				{
					// ...but bar doesn't
					FileSPDXIdentifier: "SPDXRef-File-bar",
					FileName:           "/bar",
				},
			},
		}
		docBytes, err := json.Marshal(doc)
		if err != nil {
			return nil, err
		}
		st = llb.Scratch().
			File(llb.Mkfile("/result.spdx", 0600, docBytes))
		def, err = st.Marshal(ctx)
		if err != nil {
			return nil, err
		}
		r, err = c.Solve(ctx, gateway.SolveRequest{
			Definition: def.ToPB(),
		})
		if err != nil {
			return nil, err
		}
		refAttest, err := r.SingleRef()
		if err != nil {
			return nil, err
		}
		_, err = ref.ToState()
		if err != nil {
			return nil, err
		}

		res.AddAttestation(pk, gateway.Attestation{
			Kind: gatewaypb.AttestationKindInToto,
			Ref:  refAttest,
			Path: "/result.spdx",
			InToto: result.InTotoAttestation{
				PredicateType: intoto.PredicateSPDX,
			},
			Metadata: map[string][]byte{
				result.AttestationSBOMCore: []byte("result"),
			},
		})

		return res, nil
	}

	// test the default fallback scanner
	target := registry + "/buildkit/testsbom:latest"
	_, err = c.Build(sb.Context(), SolveOpt{
		FrontendAttrs: map[string]string{
			"attest:sbom": "",
		},
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
	}, "", frontend, nil)
	require.NoError(t, err)

	desc, provider, err := contentutil.ProviderFromRef(target)
	require.NoError(t, err)

	imgs, err := testutil.ReadImages(sb.Context(), provider, desc)
	require.NoError(t, err)
	require.Equal(t, 2, len(imgs.Images))

	att := imgs.Find("unknown/unknown")
	attest := struct {
		intoto.StatementHeader
		Predicate spdx.Document
	}{}
	require.NoError(t, json.Unmarshal(att.LayersRaw[0], &attest))
	require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
	require.Equal(t, intoto.PredicateSPDX, attest.PredicateType)

	require.Equal(t, "DOCUMENT", string(attest.Predicate.SPDXIdentifier))
	require.Len(t, attest.Predicate.Files, 2)
	require.Equal(t, attest.Predicate.Files[0].FileName, "/foo")
	require.Regexp(t, "^layerID: sha256:", attest.Predicate.Files[0].FileComment)
	require.Equal(t, attest.Predicate.Files[1].FileName, "/bar")
	require.Empty(t, attest.Predicate.Files[1].FileComment)
}

func testMultipleCacheExports(t *testing.T, sb integration.Sandbox) {
	workers.CheckFeatureCompat(t, sb, workers.FeatureMultiCacheExport)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	registry, err := sb.NewRegistry()
	if errors.Is(err, integration.ErrRequirements) {
		t.Skip(err.Error())
	}
	require.NoError(t, err)

	busybox := llb.Image("busybox:latest")
	st := llb.Scratch()
	run := func(cmd string) {
		st = busybox.Run(llb.Shlex(cmd), llb.Dir("/wd")).AddMount("/wd", st)
	}
	run(`sh -c "echo -n foobar > const"`)
	run(`sh -c "cat /dev/urandom | head -c 100 | sha256sum > unique"`)

	def, err := st.Marshal(sb.Context())
	require.NoError(t, err)

	target := path.Join(registry, "image:test")
	target2 := path.Join(registry, "image-copy:test")
	cacheRef := path.Join(registry, "cache:test")
	cacheOutDir, cacheOutDir2 := t.TempDir(), t.TempDir()

	res, err := c.Solve(sb.Context(), def, SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target,
					"push": "true",
				},
			},
		},
		CacheExports: []CacheOptionsEntry{
			{
				Type: "local",
				Attrs: map[string]string{
					"dest": cacheOutDir,
				},
			},
			{
				Type: "local",
				Attrs: map[string]string{
					"dest": cacheOutDir2,
				},
			},
			{
				Type: "registry",
				Attrs: map[string]string{
					"ref": cacheRef,
				},
			},
			{
				Type: "inline",
			},
		},
	}, nil)
	require.NoError(t, err)

	ensureFile(t, filepath.Join(cacheOutDir, "index.json"))
	ensureFile(t, filepath.Join(cacheOutDir2, "index.json"))

	dgst := res.ExporterResponse[exptypes.ExporterImageDigestKey]

	uniqueFile, err := readFileInImage(sb.Context(), t, c, target+"@"+dgst, "/unique")
	require.NoError(t, err)

	res, err = c.Solve(sb.Context(), def, SolveOpt{
		Exports: []ExportEntry{
			{
				Type: ExporterImage,
				Attrs: map[string]string{
					"name": target2,
					"push": "true",
				},
			},
		},
		CacheExports: []CacheOptionsEntry{
			{
				Type: "inline",
			},
		},
	}, nil)
	require.NoError(t, err)

	dgst2 := res.ExporterResponse[exptypes.ExporterImageDigestKey]
	require.Equal(t, dgst, dgst2)

	destDir := t.TempDir()
	ensurePruneAll(t, c, sb)
	_, err = c.Solve(sb.Context(), def, SolveOpt{
		Exports: []ExportEntry{
			{
				Type:      ExporterLocal,
				OutputDir: destDir,
			},
		},
		CacheImports: []CacheOptionsEntry{
			{
				Type: "registry",
				Attrs: map[string]string{
					"ref": cacheRef,
				},
			},
		},
	}, nil)
	require.NoError(t, err)

	ensureFileContents(t, filepath.Join(destDir, "const"), "foobar")
	ensureFileContents(t, filepath.Join(destDir, "unique"), string(uniqueFile))
}

func testMountStubsDirectory(t *testing.T, sb integration.Sandbox) {
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	st := llb.Image("busybox:latest").
		File(llb.Mkdir("/test", 0700)).
		File(llb.Mkdir("/test/qux/", 0700)).
		Run(
			llb.Args([]string{"touch", "/test/baz/keep"}),
			// check stubs directory is removed
			llb.AddMount("/test/foo", llb.Scratch(), llb.Tmpfs()),
			// check that stubs directory are recursively removed
			llb.AddMount("/test/bar/x/y", llb.Scratch(), llb.Tmpfs()),
			// check that only empty stubs directories are removed
			llb.AddMount("/test/baz/x", llb.Scratch(), llb.Tmpfs()),
			// check that previously existing directory are not removed
			llb.AddMount("/test/qux", llb.Scratch(), llb.Tmpfs()),
		).Root()
	st = llb.Scratch().File(llb.Copy(st, "/test", "/", &llb.CopyInfo{CopyDirContentsOnly: true}))
	def, err := st.Marshal(sb.Context())
	require.NoError(t, err)

	tmpDir := t.TempDir()
	tarFile := filepath.Join(tmpDir, "out.tar")
	tarFileW, err := os.Create(tarFile)
	require.NoError(t, err)
	defer tarFileW.Close()

	_, err = c.Solve(sb.Context(), def, SolveOpt{
		Exports: []ExportEntry{
			{
				Type:   ExporterTar,
				Output: fixedWriteCloser(tarFileW),
			},
		},
	}, nil)
	require.NoError(t, err)
	tarFileW.Close()

	dt, err := os.ReadFile(tarFile)
	require.NoError(t, err)

	m, err := testutil.ReadTarToMap(dt, false)
	require.NoError(t, err)

	keys := make([]string, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}

	require.ElementsMatch(t, []string{
		"baz/",
		"baz/keep",
		"qux/",
	}, keys)
}

// https://github.com/moby/buildkit/issues/3148
func testMountStubsTimestamp(t *testing.T, sb integration.Sandbox) {
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	const sourceDateEpoch = int64(1234567890) // Fri Feb 13 11:31:30 PM UTC 2009
	st := llb.Image("busybox:latest").Run(
		llb.Args([]string{"/bin/touch", fmt.Sprintf("--date=@%d", sourceDateEpoch),
			"/bin",
			"/etc",
			"/var",
			"/var/foo",
			"/tmp",
			"/tmp/foo2",
			"/tmp/foo2/bar",
		}),
		llb.AddMount("/var/foo", llb.Scratch(), llb.Tmpfs()),
		llb.AddMount("/tmp/foo2/bar", llb.Scratch(), llb.Tmpfs()),
	)
	def, err := st.Marshal(sb.Context())
	require.NoError(t, err)

	tmpDir := t.TempDir()
	tarFile := filepath.Join(tmpDir, "out.tar")
	tarFileW, err := os.Create(tarFile)
	require.NoError(t, err)
	defer tarFileW.Close()

	_, err = c.Solve(sb.Context(), def, SolveOpt{
		Exports: []ExportEntry{
			{
				Type:   ExporterTar,
				Output: fixedWriteCloser(tarFileW),
			},
		},
	}, nil)
	require.NoError(t, err)
	tarFileW.Close()

	tarFileR, err := os.Open(tarFile)
	require.NoError(t, err)
	defer tarFileR.Close()
	tarR := tar.NewReader(tarFileR)
	touched := map[string]*tar.Header{
		"bin/": nil, // Regular dir
		"etc/": nil, // Parent of file mounts (etc/{resolv.conf, hosts})
		"var/": nil, // Parent of dir mount (var/foo/)
		"tmp/": nil, // Grandparent of dir mount (tmp/foo2/bar/)
		// No support for reproducing the timestamps of mount point directories such as var/foo/ and tmp/foo2/bar/,
		// because the touched timestamp value is lost when the mount is unmounted.
	}
	for {
		hd, err := tarR.Next()
		if errors.Is(err, io.EOF) {
			break
		}
		require.NoError(t, err)
		if x, ok := touched[hd.Name]; ok && x == nil {
			touched[hd.Name] = hd
		}
	}
	for name, hd := range touched {
		t.Logf("Verifying %q (%+v)", name, hd)
		require.NotNil(t, hd, name)
		require.Equal(t, sourceDateEpoch, hd.ModTime.Unix(), name)
	}
}

func ensureFile(t *testing.T, path string) {
	st, err := os.Stat(path)
	require.NoError(t, err, "expected file at %s", path)
	require.True(t, st.Mode().IsRegular())
}

func ensureFileContents(t *testing.T, path, expectedContents string) {
	contents, err := os.ReadFile(path)
	require.NoError(t, err)
	require.Equal(t, expectedContents, string(contents))
}

func makeSSHAgentSock(t *testing.T, agent agent.Agent) (p string, err error) {
	tmpDir := integration.Tmpdir(t)
	sockPath := filepath.Join(tmpDir, "ssh_auth_sock")

	l, err := net.Listen("unix", sockPath)
	if err != nil {
		return "", err
	}
	t.Cleanup(func() {
		require.NoError(t, l.Close())
	})

	s := &server{l: l}
	go s.run(agent)

	return sockPath, nil
}

type imageTimestamps struct {
	FromImage      []string // from img.Created and img.[]History.Created
	FromAnnotation string   // from index.Manifests[0].Annotations["org.opencontainers.image.created"]
}

func readImageTimestamps(dt []byte) (*imageTimestamps, error) {
	m, err := testutil.ReadTarToMap(dt, false)
	if err != nil {
		return nil, err
	}

	if _, ok := m["oci-layout"]; !ok {
		return nil, errors.Errorf("no oci-layout")
	}

	var index ocispecs.Index
	if err := json.Unmarshal(m["index.json"].Data, &index); err != nil {
		return nil, err
	}
	if len(index.Manifests) != 1 {
		return nil, errors.Errorf("invalid manifest count %d", len(index.Manifests))
	}

	var res imageTimestamps
	res.FromAnnotation = index.Manifests[0].Annotations[ocispecs.AnnotationCreated]

	var mfst ocispecs.Manifest
	if err := json.Unmarshal(m["blobs/sha256/"+index.Manifests[0].Digest.Hex()].Data, &mfst); err != nil {
		return nil, err
	}
	// don't unmarshal to image type so we get the original string value
	type history struct {
		Created string `json:"created"`
	}

	img := struct {
		History []history `json:"history"`
		Created string    `json:"created"`
	}{}

	if err := json.Unmarshal(m["blobs/sha256/"+mfst.Config.Digest.Hex()].Data, &img); err != nil {
		return nil, err
	}

	res.FromImage = []string{
		img.Created,
	}
	for _, h := range img.History {
		res.FromImage = append(res.FromImage, h.Created)
	}
	return &res, nil
}

type server struct {
	l net.Listener
}

func (s *server) run(a agent.Agent) error {
	for {
		c, err := s.l.Accept()
		if err != nil {
			return err
		}

		go agent.ServeAgent(a, c)
	}
}

type secModeSandbox struct{}

func (*secModeSandbox) UpdateConfigFile(in string) string {
	return in
}

type secModeInsecure struct{}

func (*secModeInsecure) UpdateConfigFile(in string) string {
	return in + "\n\ninsecure-entitlements = [\"security.insecure\"]\n"
}

var securitySandbox integration.ConfigUpdater = &secModeSandbox{}
var securityInsecure integration.ConfigUpdater = &secModeInsecure{}

type netModeHost struct{}

func (*netModeHost) UpdateConfigFile(in string) string {
	return in + "\n\ninsecure-entitlements = [\"network.host\"]\n"
}

type netModeDefault struct{}

func (*netModeDefault) UpdateConfigFile(in string) string {
	return in
}

type netModeBridgeDNS struct{}

func (*netModeBridgeDNS) UpdateConfigFile(in string) string {
	return in + `
# configure bridge networking
[worker.oci]
networkMode = "cni"
cniConfigPath = "/etc/buildkit/dns-cni.conflist"

[worker.containerd]
networkMode = "cni"
cniConfigPath = "/etc/buildkit/dns-cni.conflist"

[dns]
nameservers = ["10.11.0.1"]
`
}

var hostNetwork integration.ConfigUpdater = &netModeHost{}
var defaultNetwork integration.ConfigUpdater = &netModeDefault{}
var bridgeDNSNetwork integration.ConfigUpdater = &netModeBridgeDNS{}

func fixedWriteCloser(wc io.WriteCloser) func(map[string]string) (io.WriteCloser, error) {
	return func(map[string]string) (io.WriteCloser, error) {
		return wc, nil
	}
}

func testSourcePolicy(t *testing.T, sb integration.Sandbox) {
	requiresLinux(t)
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
		st := llb.Image("busybox:1.34.1-uclibc").File(
			llb.Copy(llb.HTTP("https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md"),
				"README.md", "README.md"))
		def, err := st.Marshal(sb.Context())
		if err != nil {
			return nil, err
		}
		return c.Solve(ctx, gateway.SolveRequest{
			Definition: def.ToPB(),
		})
	}

	type testCase struct {
		srcPol      *sourcepolicypb.Policy
		expectedErr string
	}
	testCases := []testCase{
		{
			// Valid
			srcPol: &sourcepolicypb.Policy{
				Rules: []*sourcepolicypb.Rule{
					{
						Action: sourcepolicypb.PolicyAction_CONVERT,
						Selector: &sourcepolicypb.Selector{
							Identifier: "docker-image://docker.io/library/busybox:1.34.1-uclibc",
						},
						Updates: &sourcepolicypb.Update{
							Identifier: "docker-image://docker.io/library/busybox:1.34.1-uclibc@sha256:3614ca5eacf0a3a1bcc361c939202a974b4902b9334ff36eb29ffe9011aaad83",
						},
					},
					{
						Action: sourcepolicypb.PolicyAction_CONVERT,
						Selector: &sourcepolicypb.Selector{
							Identifier: "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md",
						},
						Updates: &sourcepolicypb.Update{
							Identifier: "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md",
							Attrs:      map[string]string{"http.checksum": "sha256:6e4b94fc270e708e1068be28bd3551dc6917a4fc5a61293d51bb36e6b75c4b53"},
						},
					},
				},
			},
			expectedErr: "",
		},
		{
			// Invalid docker-image source
			srcPol: &sourcepolicypb.Policy{
				Rules: []*sourcepolicypb.Rule{
					{
						Action: sourcepolicypb.PolicyAction_CONVERT,
						Selector: &sourcepolicypb.Selector{
							Identifier: "docker-image://docker.io/library/busybox:1.34.1-uclibc",
						},
						Updates: &sourcepolicypb.Update{
							Identifier: "docker-image://docker.io/library/busybox:1.34.1-uclibc@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", // invalid
						},
					},
				},
			},
			expectedErr: "docker.io/library/busybox:1.34.1-uclibc@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: not found",
		},
		{
			// Invalid http source
			srcPol: &sourcepolicypb.Policy{
				Rules: []*sourcepolicypb.Rule{
					{
						Action: sourcepolicypb.PolicyAction_CONVERT,
						Selector: &sourcepolicypb.Selector{
							Identifier: "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md",
						},
						Updates: &sourcepolicypb.Update{
							Attrs: map[string]string{pb.AttrHTTPChecksum: "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"}, // invalid
						},
					},
				},
			},
			expectedErr: "digest mismatch sha256:6e4b94fc270e708e1068be28bd3551dc6917a4fc5a61293d51bb36e6b75c4b53: sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
		},
	}
	for i, tc := range testCases {
		tc := tc
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			_, err = c.Build(sb.Context(), SolveOpt{SourcePolicy: tc.srcPol}, "", frontend, nil)
			if tc.expectedErr == "" {
				require.NoError(t, err)
			} else {
				require.Error(t, err)
				require.Contains(t, err.Error(), tc.expectedErr)
			}
		})
	}

	t.Run("Frontend policies", func(t *testing.T) {
		t.Run("deny http", func(t *testing.T) {
			denied := "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md"
			frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
				st := llb.Image("busybox:1.34.1-uclibc").File(
					llb.Copy(llb.HTTP(denied),
						"README.md", "README.md"))
				def, err := st.Marshal(sb.Context())
				if err != nil {
					return nil, err
				}
				return c.Solve(ctx, gateway.SolveRequest{
					Definition: def.ToPB(),
					SourcePolicies: []*sourcepolicypb.Policy{{
						Rules: []*sourcepolicypb.Rule{
							{
								Action: sourcepolicypb.PolicyAction_DENY,
								Selector: &sourcepolicypb.Selector{
									Identifier: denied,
								},
							},
						},
					}},
				})
			}

			_, err = c.Build(sb.Context(), SolveOpt{}, "", frontend, nil)
			require.ErrorContains(t, err, sourcepolicy.ErrSourceDenied.Error())
		})
		t.Run("resolve image config", func(t *testing.T) {
			frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
				const (
					origRef    = "docker.io/library/busybox:1.34.1-uclibc"
					updatedRef = "docker.io/library/busybox:latest"
				)
				pol := []*sourcepolicypb.Policy{
					{
						Rules: []*sourcepolicypb.Rule{
							{
								Action: sourcepolicypb.PolicyAction_DENY,
								Selector: &sourcepolicypb.Selector{
									Identifier: "*",
								},
							},
							{
								Action: sourcepolicypb.PolicyAction_ALLOW,
								Selector: &sourcepolicypb.Selector{
									Identifier: "docker-image://" + updatedRef + "*",
								},
							},
							{
								Action: sourcepolicypb.PolicyAction_CONVERT,
								Selector: &sourcepolicypb.Selector{
									Identifier: "docker-image://" + origRef,
								},
								Updates: &sourcepolicypb.Update{
									Identifier: "docker-image://" + updatedRef,
								},
							},
						},
					},
				}

				ref, dgst, _, err := c.ResolveImageConfig(ctx, origRef, llb.ResolveImageConfigOpt{
					SourcePolicies: pol,
				})
				if err != nil {
					return nil, err
				}
				require.Equal(t, updatedRef, ref)
				st := llb.Image(ref + "@" + dgst.String())
				def, err := st.Marshal(sb.Context())
				if err != nil {
					return nil, err
				}
				return c.Solve(ctx, gateway.SolveRequest{
					Definition:     def.ToPB(),
					SourcePolicies: pol,
				})
			}
			_, err = c.Build(sb.Context(), SolveOpt{}, "", frontend, nil)
			require.NoError(t, err)
		})
	})
}

func testLLBMountPerformance(t *testing.T, sb integration.Sandbox) {
	c, err := New(sb.Context(), sb.Address())
	require.NoError(t, err)
	defer c.Close()

	mntInput := llb.Image("busybox:latest")
	st := llb.Image("busybox:latest")
	var mnts []llb.State
	for i := 0; i < 20; i++ {
		execSt := st.Run(
			llb.Args([]string{"true"}),
		)
		mnts = append(mnts, mntInput)
		for j := range mnts {
			mnts[j] = execSt.AddMount(fmt.Sprintf("/tmp/bin%d", j), mnts[j], llb.SourcePath("/bin"))
		}
		st = execSt.Root()
	}

	def, err := st.Marshal(sb.Context())
	require.NoError(t, err)

	timeoutCtx, cancel := context.WithTimeout(sb.Context(), time.Minute)
	defer cancel()
	_, err = c.Solve(timeoutCtx, def, SolveOpt{}, nil)
	require.NoError(t, err)
}

func testClientCustomGRPCOpts(t *testing.T, sb integration.Sandbox) {
	var interceptedMethods []string
	intercept := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
		interceptedMethods = append(interceptedMethods, method)
		return invoker(ctx, method, req, reply, cc, opts...)
	}
	c, err := New(sb.Context(), sb.Address(), WithGRPCDialOption(grpc.WithChainUnaryInterceptor(intercept)))
	require.NoError(t, err)
	defer c.Close()

	st := llb.Image("busybox:latest")
	def, err := st.Marshal(sb.Context())
	require.NoError(t, err)
	_, err = c.Solve(sb.Context(), def, SolveOpt{}, nil)
	require.NoError(t, err)

	require.Contains(t, interceptedMethods, "/moby.buildkit.v1.Control/Solve")
}

repository: moby/buildkit

repo_name: moby/buildkit

gha_language: Go

extension: go


text:
include(FetchContent)

FetchContent_Declare(
    pybind11
    URL https://github.com/Oneflow-Inc/pybind11/archive/1534e17.zip
)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
    FetchContent_Populate(pybind11)
    add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()

repository: ashing-zhang/oneflow

license_type: permissive

repo_name: ashing-zhang/oneflow

branch_name: refs/heads/master

extension: cmake


text:
# Recipe for compiling beignet for Minnowboard Max

require beignet.inc

EXTRA_OECMAKE_append = " -DGEN_PCI_ID=0x0F31"

license: MIT

repository: intel/intel-iot-refkit

repo_name: intel/intel-iot-refkit

gha_license_id: MIT

gha_language: Python

extension: bb


text:
// DO NOT EDIT THIS FILE. GENERATED BY xgen.

// +build k210

package uart

import (
	"embedded/mmio"
	"unsafe"

	"github.com/embeddedgo/kendryte/p/bus"
	"github.com/embeddedgo/kendryte/p/mmap"
)

type Periph struct {
	RBR_DLL_THR RRBR_DLL_THR
	DLH_IER     RDLH_IER
	FCR_IIR     RFCR_IIR
	LCR         RLCR
	MCR         RMCR
	LSR         RLSR
	MSR         RMSR
	SCR         RSCR
	LPDLL       RLPDLL
	LPDLH       RLPDLH
	_           [2]uint32
	SRBR_STHR   [16]RSRBR_STHR
	FAR         RFAR
	TFR         RTFR
	RFW         RRFW
	USR         RUSR
	TFL         RTFL
	RFL         RRFL
	SRR         RSRR
	SRTS        RSRTS
	SBCR        RSBCR
	SDMAM       RSDMAM
	SFE         RSFE
	SRT         RSRT
	STET        RSTET
	HTX         RHTX
	DMASA       RDMASA
	TCR         RTCR
	DE_EN       RDE_EN
	RE_EN       RRE_EN
	DET         RDET
	TAT         RTAT
	DLF         RDLF
	RAR         RRAR
	TAR         RTAR
	LCR_EXT     RLCR_EXT
	_           [9]uint32
	CPR         RCPR
	UCV         RUCV
	CTR         RCTR
}

func UART1() *Periph { return (*Periph)(unsafe.Pointer(uintptr(mmap.UART1_BASE))) }
func UART2() *Periph { return (*Periph)(unsafe.Pointer(uintptr(mmap.UART2_BASE))) }
func UART3() *Periph { return (*Periph)(unsafe.Pointer(uintptr(mmap.UART3_BASE))) }

func (p *Periph) BaseAddr() uintptr {
	return uintptr(unsafe.Pointer(p))
}

func (p *Periph) Bus() bus.Bus {
	return bus.APB0
}

type RBR_DLL_THR uint32

type RRBR_DLL_THR struct{ mmio.U32 }

func (r *RRBR_DLL_THR) LoadBits(mask RBR_DLL_THR) RBR_DLL_THR {
	return RBR_DLL_THR(r.U32.LoadBits(uint32(mask)))
}
func (r *RRBR_DLL_THR) StoreBits(mask, b RBR_DLL_THR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RRBR_DLL_THR) SetBits(mask RBR_DLL_THR)      { r.U32.SetBits(uint32(mask)) }
func (r *RRBR_DLL_THR) ClearBits(mask RBR_DLL_THR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RRBR_DLL_THR) Load() RBR_DLL_THR             { return RBR_DLL_THR(r.U32.Load()) }
func (r *RRBR_DLL_THR) Store(b RBR_DLL_THR)           { r.U32.Store(uint32(b)) }

type RMRBR_DLL_THR struct{ mmio.UM32 }

func (rm RMRBR_DLL_THR) Load() RBR_DLL_THR   { return RBR_DLL_THR(rm.UM32.Load()) }
func (rm RMRBR_DLL_THR) Store(b RBR_DLL_THR) { rm.UM32.Store(uint32(b)) }

type DLH_IER uint32

type RDLH_IER struct{ mmio.U32 }

func (r *RDLH_IER) LoadBits(mask DLH_IER) DLH_IER { return DLH_IER(r.U32.LoadBits(uint32(mask))) }
func (r *RDLH_IER) StoreBits(mask, b DLH_IER)     { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RDLH_IER) SetBits(mask DLH_IER)          { r.U32.SetBits(uint32(mask)) }
func (r *RDLH_IER) ClearBits(mask DLH_IER)        { r.U32.ClearBits(uint32(mask)) }
func (r *RDLH_IER) Load() DLH_IER                 { return DLH_IER(r.U32.Load()) }
func (r *RDLH_IER) Store(b DLH_IER)               { r.U32.Store(uint32(b)) }

type RMDLH_IER struct{ mmio.UM32 }

func (rm RMDLH_IER) Load() DLH_IER   { return DLH_IER(rm.UM32.Load()) }
func (rm RMDLH_IER) Store(b DLH_IER) { rm.UM32.Store(uint32(b)) }

type FCR_IIR uint32

type RFCR_IIR struct{ mmio.U32 }

func (r *RFCR_IIR) LoadBits(mask FCR_IIR) FCR_IIR { return FCR_IIR(r.U32.LoadBits(uint32(mask))) }
func (r *RFCR_IIR) StoreBits(mask, b FCR_IIR)     { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RFCR_IIR) SetBits(mask FCR_IIR)          { r.U32.SetBits(uint32(mask)) }
func (r *RFCR_IIR) ClearBits(mask FCR_IIR)        { r.U32.ClearBits(uint32(mask)) }
func (r *RFCR_IIR) Load() FCR_IIR                 { return FCR_IIR(r.U32.Load()) }
func (r *RFCR_IIR) Store(b FCR_IIR)               { r.U32.Store(uint32(b)) }

type RMFCR_IIR struct{ mmio.UM32 }

func (rm RMFCR_IIR) Load() FCR_IIR   { return FCR_IIR(rm.UM32.Load()) }
func (rm RMFCR_IIR) Store(b FCR_IIR) { rm.UM32.Store(uint32(b)) }

type LCR uint32

type RLCR struct{ mmio.U32 }

func (r *RLCR) LoadBits(mask LCR) LCR { return LCR(r.U32.LoadBits(uint32(mask))) }
func (r *RLCR) StoreBits(mask, b LCR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RLCR) SetBits(mask LCR)      { r.U32.SetBits(uint32(mask)) }
func (r *RLCR) ClearBits(mask LCR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RLCR) Load() LCR             { return LCR(r.U32.Load()) }
func (r *RLCR) Store(b LCR)           { r.U32.Store(uint32(b)) }

type RMLCR struct{ mmio.UM32 }

func (rm RMLCR) Load() LCR   { return LCR(rm.UM32.Load()) }
func (rm RMLCR) Store(b LCR) { rm.UM32.Store(uint32(b)) }

type MCR uint32

type RMCR struct{ mmio.U32 }

func (r *RMCR) LoadBits(mask MCR) MCR { return MCR(r.U32.LoadBits(uint32(mask))) }
func (r *RMCR) StoreBits(mask, b MCR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RMCR) SetBits(mask MCR)      { r.U32.SetBits(uint32(mask)) }
func (r *RMCR) ClearBits(mask MCR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RMCR) Load() MCR             { return MCR(r.U32.Load()) }
func (r *RMCR) Store(b MCR)           { r.U32.Store(uint32(b)) }

type RMMCR struct{ mmio.UM32 }

func (rm RMMCR) Load() MCR   { return MCR(rm.UM32.Load()) }
func (rm RMMCR) Store(b MCR) { rm.UM32.Store(uint32(b)) }

type LSR uint32

type RLSR struct{ mmio.U32 }

func (r *RLSR) LoadBits(mask LSR) LSR { return LSR(r.U32.LoadBits(uint32(mask))) }
func (r *RLSR) StoreBits(mask, b LSR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RLSR) SetBits(mask LSR)      { r.U32.SetBits(uint32(mask)) }
func (r *RLSR) ClearBits(mask LSR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RLSR) Load() LSR             { return LSR(r.U32.Load()) }
func (r *RLSR) Store(b LSR)           { r.U32.Store(uint32(b)) }

type RMLSR struct{ mmio.UM32 }

func (rm RMLSR) Load() LSR   { return LSR(rm.UM32.Load()) }
func (rm RMLSR) Store(b LSR) { rm.UM32.Store(uint32(b)) }

type MSR uint32

type RMSR struct{ mmio.U32 }

func (r *RMSR) LoadBits(mask MSR) MSR { return MSR(r.U32.LoadBits(uint32(mask))) }
func (r *RMSR) StoreBits(mask, b MSR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RMSR) SetBits(mask MSR)      { r.U32.SetBits(uint32(mask)) }
func (r *RMSR) ClearBits(mask MSR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RMSR) Load() MSR             { return MSR(r.U32.Load()) }
func (r *RMSR) Store(b MSR)           { r.U32.Store(uint32(b)) }

type RMMSR struct{ mmio.UM32 }

func (rm RMMSR) Load() MSR   { return MSR(rm.UM32.Load()) }
func (rm RMMSR) Store(b MSR) { rm.UM32.Store(uint32(b)) }

type SCR uint32

type RSCR struct{ mmio.U32 }

func (r *RSCR) LoadBits(mask SCR) SCR { return SCR(r.U32.LoadBits(uint32(mask))) }
func (r *RSCR) StoreBits(mask, b SCR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSCR) SetBits(mask SCR)      { r.U32.SetBits(uint32(mask)) }
func (r *RSCR) ClearBits(mask SCR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RSCR) Load() SCR             { return SCR(r.U32.Load()) }
func (r *RSCR) Store(b SCR)           { r.U32.Store(uint32(b)) }

type RMSCR struct{ mmio.UM32 }

func (rm RMSCR) Load() SCR   { return SCR(rm.UM32.Load()) }
func (rm RMSCR) Store(b SCR) { rm.UM32.Store(uint32(b)) }

type LPDLL uint32

type RLPDLL struct{ mmio.U32 }

func (r *RLPDLL) LoadBits(mask LPDLL) LPDLL { return LPDLL(r.U32.LoadBits(uint32(mask))) }
func (r *RLPDLL) StoreBits(mask, b LPDLL)   { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RLPDLL) SetBits(mask LPDLL)        { r.U32.SetBits(uint32(mask)) }
func (r *RLPDLL) ClearBits(mask LPDLL)      { r.U32.ClearBits(uint32(mask)) }
func (r *RLPDLL) Load() LPDLL               { return LPDLL(r.U32.Load()) }
func (r *RLPDLL) Store(b LPDLL)             { r.U32.Store(uint32(b)) }

type RMLPDLL struct{ mmio.UM32 }

func (rm RMLPDLL) Load() LPDLL   { return LPDLL(rm.UM32.Load()) }
func (rm RMLPDLL) Store(b LPDLL) { rm.UM32.Store(uint32(b)) }

type LPDLH uint32

type RLPDLH struct{ mmio.U32 }

func (r *RLPDLH) LoadBits(mask LPDLH) LPDLH { return LPDLH(r.U32.LoadBits(uint32(mask))) }
func (r *RLPDLH) StoreBits(mask, b LPDLH)   { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RLPDLH) SetBits(mask LPDLH)        { r.U32.SetBits(uint32(mask)) }
func (r *RLPDLH) ClearBits(mask LPDLH)      { r.U32.ClearBits(uint32(mask)) }
func (r *RLPDLH) Load() LPDLH               { return LPDLH(r.U32.Load()) }
func (r *RLPDLH) Store(b LPDLH)             { r.U32.Store(uint32(b)) }

type RMLPDLH struct{ mmio.UM32 }

func (rm RMLPDLH) Load() LPDLH   { return LPDLH(rm.UM32.Load()) }
func (rm RMLPDLH) Store(b LPDLH) { rm.UM32.Store(uint32(b)) }

type SRBR_STHR uint32

type RSRBR_STHR struct{ mmio.U32 }

func (r *RSRBR_STHR) LoadBits(mask SRBR_STHR) SRBR_STHR {
	return SRBR_STHR(r.U32.LoadBits(uint32(mask)))
}
func (r *RSRBR_STHR) StoreBits(mask, b SRBR_STHR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSRBR_STHR) SetBits(mask SRBR_STHR)      { r.U32.SetBits(uint32(mask)) }
func (r *RSRBR_STHR) ClearBits(mask SRBR_STHR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RSRBR_STHR) Load() SRBR_STHR             { return SRBR_STHR(r.U32.Load()) }
func (r *RSRBR_STHR) Store(b SRBR_STHR)           { r.U32.Store(uint32(b)) }

type RMSRBR_STHR struct{ mmio.UM32 }

func (rm RMSRBR_STHR) Load() SRBR_STHR   { return SRBR_STHR(rm.UM32.Load()) }
func (rm RMSRBR_STHR) Store(b SRBR_STHR) { rm.UM32.Store(uint32(b)) }

type FAR uint32

type RFAR struct{ mmio.U32 }

func (r *RFAR) LoadBits(mask FAR) FAR { return FAR(r.U32.LoadBits(uint32(mask))) }
func (r *RFAR) StoreBits(mask, b FAR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RFAR) SetBits(mask FAR)      { r.U32.SetBits(uint32(mask)) }
func (r *RFAR) ClearBits(mask FAR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RFAR) Load() FAR             { return FAR(r.U32.Load()) }
func (r *RFAR) Store(b FAR)           { r.U32.Store(uint32(b)) }

type RMFAR struct{ mmio.UM32 }

func (rm RMFAR) Load() FAR   { return FAR(rm.UM32.Load()) }
func (rm RMFAR) Store(b FAR) { rm.UM32.Store(uint32(b)) }

type TFR uint32

type RTFR struct{ mmio.U32 }

func (r *RTFR) LoadBits(mask TFR) TFR { return TFR(r.U32.LoadBits(uint32(mask))) }
func (r *RTFR) StoreBits(mask, b TFR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RTFR) SetBits(mask TFR)      { r.U32.SetBits(uint32(mask)) }
func (r *RTFR) ClearBits(mask TFR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RTFR) Load() TFR             { return TFR(r.U32.Load()) }
func (r *RTFR) Store(b TFR)           { r.U32.Store(uint32(b)) }

type RMTFR struct{ mmio.UM32 }

func (rm RMTFR) Load() TFR   { return TFR(rm.UM32.Load()) }
func (rm RMTFR) Store(b TFR) { rm.UM32.Store(uint32(b)) }

type RFW uint32

type RRFW struct{ mmio.U32 }

func (r *RRFW) LoadBits(mask RFW) RFW { return RFW(r.U32.LoadBits(uint32(mask))) }
func (r *RRFW) StoreBits(mask, b RFW) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RRFW) SetBits(mask RFW)      { r.U32.SetBits(uint32(mask)) }
func (r *RRFW) ClearBits(mask RFW)    { r.U32.ClearBits(uint32(mask)) }
func (r *RRFW) Load() RFW             { return RFW(r.U32.Load()) }
func (r *RRFW) Store(b RFW)           { r.U32.Store(uint32(b)) }

type RMRFW struct{ mmio.UM32 }

func (rm RMRFW) Load() RFW   { return RFW(rm.UM32.Load()) }
func (rm RMRFW) Store(b RFW) { rm.UM32.Store(uint32(b)) }

type USR uint32

type RUSR struct{ mmio.U32 }

func (r *RUSR) LoadBits(mask USR) USR { return USR(r.U32.LoadBits(uint32(mask))) }
func (r *RUSR) StoreBits(mask, b USR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RUSR) SetBits(mask USR)      { r.U32.SetBits(uint32(mask)) }
func (r *RUSR) ClearBits(mask USR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RUSR) Load() USR             { return USR(r.U32.Load()) }
func (r *RUSR) Store(b USR)           { r.U32.Store(uint32(b)) }

type RMUSR struct{ mmio.UM32 }

func (rm RMUSR) Load() USR   { return USR(rm.UM32.Load()) }
func (rm RMUSR) Store(b USR) { rm.UM32.Store(uint32(b)) }

type TFL uint32

type RTFL struct{ mmio.U32 }

func (r *RTFL) LoadBits(mask TFL) TFL { return TFL(r.U32.LoadBits(uint32(mask))) }
func (r *RTFL) StoreBits(mask, b TFL) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RTFL) SetBits(mask TFL)      { r.U32.SetBits(uint32(mask)) }
func (r *RTFL) ClearBits(mask TFL)    { r.U32.ClearBits(uint32(mask)) }
func (r *RTFL) Load() TFL             { return TFL(r.U32.Load()) }
func (r *RTFL) Store(b TFL)           { r.U32.Store(uint32(b)) }

type RMTFL struct{ mmio.UM32 }

func (rm RMTFL) Load() TFL   { return TFL(rm.UM32.Load()) }
func (rm RMTFL) Store(b TFL) { rm.UM32.Store(uint32(b)) }

type RFL uint32

type RRFL struct{ mmio.U32 }

func (r *RRFL) LoadBits(mask RFL) RFL { return RFL(r.U32.LoadBits(uint32(mask))) }
func (r *RRFL) StoreBits(mask, b RFL) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RRFL) SetBits(mask RFL)      { r.U32.SetBits(uint32(mask)) }
func (r *RRFL) ClearBits(mask RFL)    { r.U32.ClearBits(uint32(mask)) }
func (r *RRFL) Load() RFL             { return RFL(r.U32.Load()) }
func (r *RRFL) Store(b RFL)           { r.U32.Store(uint32(b)) }

type RMRFL struct{ mmio.UM32 }

func (rm RMRFL) Load() RFL   { return RFL(rm.UM32.Load()) }
func (rm RMRFL) Store(b RFL) { rm.UM32.Store(uint32(b)) }

type SRR uint32

type RSRR struct{ mmio.U32 }

func (r *RSRR) LoadBits(mask SRR) SRR { return SRR(r.U32.LoadBits(uint32(mask))) }
func (r *RSRR) StoreBits(mask, b SRR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSRR) SetBits(mask SRR)      { r.U32.SetBits(uint32(mask)) }
func (r *RSRR) ClearBits(mask SRR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RSRR) Load() SRR             { return SRR(r.U32.Load()) }
func (r *RSRR) Store(b SRR)           { r.U32.Store(uint32(b)) }

type RMSRR struct{ mmio.UM32 }

func (rm RMSRR) Load() SRR   { return SRR(rm.UM32.Load()) }
func (rm RMSRR) Store(b SRR) { rm.UM32.Store(uint32(b)) }

type SRTS uint32

type RSRTS struct{ mmio.U32 }

func (r *RSRTS) LoadBits(mask SRTS) SRTS { return SRTS(r.U32.LoadBits(uint32(mask))) }
func (r *RSRTS) StoreBits(mask, b SRTS)  { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSRTS) SetBits(mask SRTS)       { r.U32.SetBits(uint32(mask)) }
func (r *RSRTS) ClearBits(mask SRTS)     { r.U32.ClearBits(uint32(mask)) }
func (r *RSRTS) Load() SRTS              { return SRTS(r.U32.Load()) }
func (r *RSRTS) Store(b SRTS)            { r.U32.Store(uint32(b)) }

type RMSRTS struct{ mmio.UM32 }

func (rm RMSRTS) Load() SRTS   { return SRTS(rm.UM32.Load()) }
func (rm RMSRTS) Store(b SRTS) { rm.UM32.Store(uint32(b)) }

type SBCR uint32

type RSBCR struct{ mmio.U32 }

func (r *RSBCR) LoadBits(mask SBCR) SBCR { return SBCR(r.U32.LoadBits(uint32(mask))) }
func (r *RSBCR) StoreBits(mask, b SBCR)  { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSBCR) SetBits(mask SBCR)       { r.U32.SetBits(uint32(mask)) }
func (r *RSBCR) ClearBits(mask SBCR)     { r.U32.ClearBits(uint32(mask)) }
func (r *RSBCR) Load() SBCR              { return SBCR(r.U32.Load()) }
func (r *RSBCR) Store(b SBCR)            { r.U32.Store(uint32(b)) }

type RMSBCR struct{ mmio.UM32 }

func (rm RMSBCR) Load() SBCR   { return SBCR(rm.UM32.Load()) }
func (rm RMSBCR) Store(b SBCR) { rm.UM32.Store(uint32(b)) }

type SDMAM uint32

type RSDMAM struct{ mmio.U32 }

func (r *RSDMAM) LoadBits(mask SDMAM) SDMAM { return SDMAM(r.U32.LoadBits(uint32(mask))) }
func (r *RSDMAM) StoreBits(mask, b SDMAM)   { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSDMAM) SetBits(mask SDMAM)        { r.U32.SetBits(uint32(mask)) }
func (r *RSDMAM) ClearBits(mask SDMAM)      { r.U32.ClearBits(uint32(mask)) }
func (r *RSDMAM) Load() SDMAM               { return SDMAM(r.U32.Load()) }
func (r *RSDMAM) Store(b SDMAM)             { r.U32.Store(uint32(b)) }

type RMSDMAM struct{ mmio.UM32 }

func (rm RMSDMAM) Load() SDMAM   { return SDMAM(rm.UM32.Load()) }
func (rm RMSDMAM) Store(b SDMAM) { rm.UM32.Store(uint32(b)) }

type SFE uint32

type RSFE struct{ mmio.U32 }

func (r *RSFE) LoadBits(mask SFE) SFE { return SFE(r.U32.LoadBits(uint32(mask))) }
func (r *RSFE) StoreBits(mask, b SFE) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSFE) SetBits(mask SFE)      { r.U32.SetBits(uint32(mask)) }
func (r *RSFE) ClearBits(mask SFE)    { r.U32.ClearBits(uint32(mask)) }
func (r *RSFE) Load() SFE             { return SFE(r.U32.Load()) }
func (r *RSFE) Store(b SFE)           { r.U32.Store(uint32(b)) }

type RMSFE struct{ mmio.UM32 }

func (rm RMSFE) Load() SFE   { return SFE(rm.UM32.Load()) }
func (rm RMSFE) Store(b SFE) { rm.UM32.Store(uint32(b)) }

type SRT uint32

type RSRT struct{ mmio.U32 }

func (r *RSRT) LoadBits(mask SRT) SRT { return SRT(r.U32.LoadBits(uint32(mask))) }
func (r *RSRT) StoreBits(mask, b SRT) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSRT) SetBits(mask SRT)      { r.U32.SetBits(uint32(mask)) }
func (r *RSRT) ClearBits(mask SRT)    { r.U32.ClearBits(uint32(mask)) }
func (r *RSRT) Load() SRT             { return SRT(r.U32.Load()) }
func (r *RSRT) Store(b SRT)           { r.U32.Store(uint32(b)) }

type RMSRT struct{ mmio.UM32 }

func (rm RMSRT) Load() SRT   { return SRT(rm.UM32.Load()) }
func (rm RMSRT) Store(b SRT) { rm.UM32.Store(uint32(b)) }

type STET uint32

type RSTET struct{ mmio.U32 }

func (r *RSTET) LoadBits(mask STET) STET { return STET(r.U32.LoadBits(uint32(mask))) }
func (r *RSTET) StoreBits(mask, b STET)  { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RSTET) SetBits(mask STET)       { r.U32.SetBits(uint32(mask)) }
func (r *RSTET) ClearBits(mask STET)     { r.U32.ClearBits(uint32(mask)) }
func (r *RSTET) Load() STET              { return STET(r.U32.Load()) }
func (r *RSTET) Store(b STET)            { r.U32.Store(uint32(b)) }

type RMSTET struct{ mmio.UM32 }

func (rm RMSTET) Load() STET   { return STET(rm.UM32.Load()) }
func (rm RMSTET) Store(b STET) { rm.UM32.Store(uint32(b)) }

type HTX uint32

type RHTX struct{ mmio.U32 }

func (r *RHTX) LoadBits(mask HTX) HTX { return HTX(r.U32.LoadBits(uint32(mask))) }
func (r *RHTX) StoreBits(mask, b HTX) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RHTX) SetBits(mask HTX)      { r.U32.SetBits(uint32(mask)) }
func (r *RHTX) ClearBits(mask HTX)    { r.U32.ClearBits(uint32(mask)) }
func (r *RHTX) Load() HTX             { return HTX(r.U32.Load()) }
func (r *RHTX) Store(b HTX)           { r.U32.Store(uint32(b)) }

type RMHTX struct{ mmio.UM32 }

func (rm RMHTX) Load() HTX   { return HTX(rm.UM32.Load()) }
func (rm RMHTX) Store(b HTX) { rm.UM32.Store(uint32(b)) }

type DMASA uint32

type RDMASA struct{ mmio.U32 }

func (r *RDMASA) LoadBits(mask DMASA) DMASA { return DMASA(r.U32.LoadBits(uint32(mask))) }
func (r *RDMASA) StoreBits(mask, b DMASA)   { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RDMASA) SetBits(mask DMASA)        { r.U32.SetBits(uint32(mask)) }
func (r *RDMASA) ClearBits(mask DMASA)      { r.U32.ClearBits(uint32(mask)) }
func (r *RDMASA) Load() DMASA               { return DMASA(r.U32.Load()) }
func (r *RDMASA) Store(b DMASA)             { r.U32.Store(uint32(b)) }

type RMDMASA struct{ mmio.UM32 }

func (rm RMDMASA) Load() DMASA   { return DMASA(rm.UM32.Load()) }
func (rm RMDMASA) Store(b DMASA) { rm.UM32.Store(uint32(b)) }

type TCR uint32

type RTCR struct{ mmio.U32 }

func (r *RTCR) LoadBits(mask TCR) TCR { return TCR(r.U32.LoadBits(uint32(mask))) }
func (r *RTCR) StoreBits(mask, b TCR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RTCR) SetBits(mask TCR)      { r.U32.SetBits(uint32(mask)) }
func (r *RTCR) ClearBits(mask TCR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RTCR) Load() TCR             { return TCR(r.U32.Load()) }
func (r *RTCR) Store(b TCR)           { r.U32.Store(uint32(b)) }

type RMTCR struct{ mmio.UM32 }

func (rm RMTCR) Load() TCR   { return TCR(rm.UM32.Load()) }
func (rm RMTCR) Store(b TCR) { rm.UM32.Store(uint32(b)) }

type DE_EN uint32

type RDE_EN struct{ mmio.U32 }

func (r *RDE_EN) LoadBits(mask DE_EN) DE_EN { return DE_EN(r.U32.LoadBits(uint32(mask))) }
func (r *RDE_EN) StoreBits(mask, b DE_EN)   { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RDE_EN) SetBits(mask DE_EN)        { r.U32.SetBits(uint32(mask)) }
func (r *RDE_EN) ClearBits(mask DE_EN)      { r.U32.ClearBits(uint32(mask)) }
func (r *RDE_EN) Load() DE_EN               { return DE_EN(r.U32.Load()) }
func (r *RDE_EN) Store(b DE_EN)             { r.U32.Store(uint32(b)) }

type RMDE_EN struct{ mmio.UM32 }

func (rm RMDE_EN) Load() DE_EN   { return DE_EN(rm.UM32.Load()) }
func (rm RMDE_EN) Store(b DE_EN) { rm.UM32.Store(uint32(b)) }

type RE_EN uint32

type RRE_EN struct{ mmio.U32 }

func (r *RRE_EN) LoadBits(mask RE_EN) RE_EN { return RE_EN(r.U32.LoadBits(uint32(mask))) }
func (r *RRE_EN) StoreBits(mask, b RE_EN)   { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RRE_EN) SetBits(mask RE_EN)        { r.U32.SetBits(uint32(mask)) }
func (r *RRE_EN) ClearBits(mask RE_EN)      { r.U32.ClearBits(uint32(mask)) }
func (r *RRE_EN) Load() RE_EN               { return RE_EN(r.U32.Load()) }
func (r *RRE_EN) Store(b RE_EN)             { r.U32.Store(uint32(b)) }

type RMRE_EN struct{ mmio.UM32 }

func (rm RMRE_EN) Load() RE_EN   { return RE_EN(rm.UM32.Load()) }
func (rm RMRE_EN) Store(b RE_EN) { rm.UM32.Store(uint32(b)) }

type DET uint32

type RDET struct{ mmio.U32 }

func (r *RDET) LoadBits(mask DET) DET { return DET(r.U32.LoadBits(uint32(mask))) }
func (r *RDET) StoreBits(mask, b DET) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RDET) SetBits(mask DET)      { r.U32.SetBits(uint32(mask)) }
func (r *RDET) ClearBits(mask DET)    { r.U32.ClearBits(uint32(mask)) }
func (r *RDET) Load() DET             { return DET(r.U32.Load()) }
func (r *RDET) Store(b DET)           { r.U32.Store(uint32(b)) }

type RMDET struct{ mmio.UM32 }

func (rm RMDET) Load() DET   { return DET(rm.UM32.Load()) }
func (rm RMDET) Store(b DET) { rm.UM32.Store(uint32(b)) }

type TAT uint32

type RTAT struct{ mmio.U32 }

func (r *RTAT) LoadBits(mask TAT) TAT { return TAT(r.U32.LoadBits(uint32(mask))) }
func (r *RTAT) StoreBits(mask, b TAT) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RTAT) SetBits(mask TAT)      { r.U32.SetBits(uint32(mask)) }
func (r *RTAT) ClearBits(mask TAT)    { r.U32.ClearBits(uint32(mask)) }
func (r *RTAT) Load() TAT             { return TAT(r.U32.Load()) }
func (r *RTAT) Store(b TAT)           { r.U32.Store(uint32(b)) }

type RMTAT struct{ mmio.UM32 }

func (rm RMTAT) Load() TAT   { return TAT(rm.UM32.Load()) }
func (rm RMTAT) Store(b TAT) { rm.UM32.Store(uint32(b)) }

type DLF uint32

type RDLF struct{ mmio.U32 }

func (r *RDLF) LoadBits(mask DLF) DLF { return DLF(r.U32.LoadBits(uint32(mask))) }
func (r *RDLF) StoreBits(mask, b DLF) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RDLF) SetBits(mask DLF)      { r.U32.SetBits(uint32(mask)) }
func (r *RDLF) ClearBits(mask DLF)    { r.U32.ClearBits(uint32(mask)) }
func (r *RDLF) Load() DLF             { return DLF(r.U32.Load()) }
func (r *RDLF) Store(b DLF)           { r.U32.Store(uint32(b)) }

type RMDLF struct{ mmio.UM32 }

func (rm RMDLF) Load() DLF   { return DLF(rm.UM32.Load()) }
func (rm RMDLF) Store(b DLF) { rm.UM32.Store(uint32(b)) }

type RAR uint32

type RRAR struct{ mmio.U32 }

func (r *RRAR) LoadBits(mask RAR) RAR { return RAR(r.U32.LoadBits(uint32(mask))) }
func (r *RRAR) StoreBits(mask, b RAR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RRAR) SetBits(mask RAR)      { r.U32.SetBits(uint32(mask)) }
func (r *RRAR) ClearBits(mask RAR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RRAR) Load() RAR             { return RAR(r.U32.Load()) }
func (r *RRAR) Store(b RAR)           { r.U32.Store(uint32(b)) }

type RMRAR struct{ mmio.UM32 }

func (rm RMRAR) Load() RAR   { return RAR(rm.UM32.Load()) }
func (rm RMRAR) Store(b RAR) { rm.UM32.Store(uint32(b)) }

type TAR uint32

type RTAR struct{ mmio.U32 }

func (r *RTAR) LoadBits(mask TAR) TAR { return TAR(r.U32.LoadBits(uint32(mask))) }
func (r *RTAR) StoreBits(mask, b TAR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RTAR) SetBits(mask TAR)      { r.U32.SetBits(uint32(mask)) }
func (r *RTAR) ClearBits(mask TAR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RTAR) Load() TAR             { return TAR(r.U32.Load()) }
func (r *RTAR) Store(b TAR)           { r.U32.Store(uint32(b)) }

type RMTAR struct{ mmio.UM32 }

func (rm RMTAR) Load() TAR   { return TAR(rm.UM32.Load()) }
func (rm RMTAR) Store(b TAR) { rm.UM32.Store(uint32(b)) }

type LCR_EXT uint32

type RLCR_EXT struct{ mmio.U32 }

func (r *RLCR_EXT) LoadBits(mask LCR_EXT) LCR_EXT { return LCR_EXT(r.U32.LoadBits(uint32(mask))) }
func (r *RLCR_EXT) StoreBits(mask, b LCR_EXT)     { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RLCR_EXT) SetBits(mask LCR_EXT)          { r.U32.SetBits(uint32(mask)) }
func (r *RLCR_EXT) ClearBits(mask LCR_EXT)        { r.U32.ClearBits(uint32(mask)) }
func (r *RLCR_EXT) Load() LCR_EXT                 { return LCR_EXT(r.U32.Load()) }
func (r *RLCR_EXT) Store(b LCR_EXT)               { r.U32.Store(uint32(b)) }

type RMLCR_EXT struct{ mmio.UM32 }

func (rm RMLCR_EXT) Load() LCR_EXT   { return LCR_EXT(rm.UM32.Load()) }
func (rm RMLCR_EXT) Store(b LCR_EXT) { rm.UM32.Store(uint32(b)) }

type CPR uint32

type RCPR struct{ mmio.U32 }

func (r *RCPR) LoadBits(mask CPR) CPR { return CPR(r.U32.LoadBits(uint32(mask))) }
func (r *RCPR) StoreBits(mask, b CPR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RCPR) SetBits(mask CPR)      { r.U32.SetBits(uint32(mask)) }
func (r *RCPR) ClearBits(mask CPR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RCPR) Load() CPR             { return CPR(r.U32.Load()) }
func (r *RCPR) Store(b CPR)           { r.U32.Store(uint32(b)) }

type RMCPR struct{ mmio.UM32 }

func (rm RMCPR) Load() CPR   { return CPR(rm.UM32.Load()) }
func (rm RMCPR) Store(b CPR) { rm.UM32.Store(uint32(b)) }

type UCV uint32

type RUCV struct{ mmio.U32 }

func (r *RUCV) LoadBits(mask UCV) UCV { return UCV(r.U32.LoadBits(uint32(mask))) }
func (r *RUCV) StoreBits(mask, b UCV) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RUCV) SetBits(mask UCV)      { r.U32.SetBits(uint32(mask)) }
func (r *RUCV) ClearBits(mask UCV)    { r.U32.ClearBits(uint32(mask)) }
func (r *RUCV) Load() UCV             { return UCV(r.U32.Load()) }
func (r *RUCV) Store(b UCV)           { r.U32.Store(uint32(b)) }

type RMUCV struct{ mmio.UM32 }

func (rm RMUCV) Load() UCV   { return UCV(rm.UM32.Load()) }
func (rm RMUCV) Store(b UCV) { rm.UM32.Store(uint32(b)) }

type CTR uint32

type RCTR struct{ mmio.U32 }

func (r *RCTR) LoadBits(mask CTR) CTR { return CTR(r.U32.LoadBits(uint32(mask))) }
func (r *RCTR) StoreBits(mask, b CTR) { r.U32.StoreBits(uint32(mask), uint32(b)) }
func (r *RCTR) SetBits(mask CTR)      { r.U32.SetBits(uint32(mask)) }
func (r *RCTR) ClearBits(mask CTR)    { r.U32.ClearBits(uint32(mask)) }
func (r *RCTR) Load() CTR             { return CTR(r.U32.Load()) }
func (r *RCTR) Store(b CTR)           { r.U32.Store(uint32(b)) }

type RMCTR struct{ mmio.UM32 }

func (rm RMCTR) Load() CTR   { return CTR(rm.UM32.Load()) }
func (rm RMCTR) Store(b CTR) { rm.UM32.Store(uint32(b)) }

repository: fjpolo/kendryte

repo_name: fjpolo/kendryte


text:
@INPROCEEDINGS{Tekusova2008a,
  author = {Tatiana Tekusova and Martin Knuth and Tobias Schreck and J\"orn Kohlhammer},
  title = {Data Quality Visualization for Multivariate Hierarchic Data},
  year = {2008},
  abstract = {In many business applications, decision makers often have to base their decisions on large amounts of data from various sources. Often, the quality of this data varies substantially, affecting the degree of certainty the analyst can put into the analyzed data values. The data quality measures may be of qualitative or quantitative nature, and consist of one or many dimensions. In this poster paper, we first present a brief survey of currently available uncertainty visualization techniques. We then present experimental results we obtained with several techniques for visualization of multidimensional data quality information, applied on multivariate hierarchic data used in an economic data analysis scenario.},
  url = {http://bib.dbvis.de/uploadedFiles/infovis08-paper.pdf},
  year = {2008},
  booktitle = {InfoVis'08: Poster at the IEEE Conference on Information Visualization}
}

repository: vis-au/treevisnet

repo_name: vis-au/treevisnet

gha_language: TeX

extension: bib


text:
export default {
  handler: `${__dirname
    .split(process.cwd())[1]
    .substring(1)
    .replace(/\\/g, '/')}/handler.main`,
  events: [
    {
      sqs: {
        arn: { 'Fn::GetAtt': ['Queue', 'Arn'] },
      },
    },
  ],
  environment: {
    JOB_STATUS_TABLE: { Ref: 'JobStatusTable' },
    JOB_LIFETIME_SECONDS: '${self:custom.jobLifetimeSeconds}',
    LOG_LEVEL: 'WARN',
  },
  iamRoleStatements: [
    {
      Effect: 'Allow',
      Action: ['dynamodb:BatchGetItem', 'dynamodb:PutItem'],
      Resource: { 'Fn::GetAtt': ['JobStatusTable', 'Arn'] },
    },
    {
      Effect: 'Allow',
      Action: ['sqs:DeleteMessage'],
      Resource: { 'Fn::GetAtt': ['Queue', 'Arn'] },
    },
  ],
  timeout: 120,
}

repository: kpeters-cbsi/serverless-templates

repo_name: kpeters-cbsi/serverless-templates

branch_name: refs/heads/main

extension: ts


text:
using Sitecore.DataExchange;

namespace TheInjectables.Foundation.PaaSPort.Azure.Pipelines
{
    public interface IAzureServicePipelineArgs
    {
        IPlugin GetResult();
    }
}

repository: dnstommy/PaaSPort

repo_name: dnstommy/PaaSPort

extension: cs


text:
using EasyLOB.Identity.Data;
using EasyLOB.Persistence;
using Microsoft.AspNet.Identity;
using System;

namespace EasyLOB.Identity.Persistence
{
    public class IdentityRoleRepository : IdentityGenericRepositoryEF<Role>
    {
        #region Methods

        public IdentityRoleRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        public override bool Create(ZOperationResult operationResult, Role entity)
        {
            try
            {
                ApplicationRole role = new ApplicationRole { Name = entity.Name };
                IdentityResult identityResult = IdentityHelperEF.RoleManager.Create(role);
                if (!identityResult.Succeeded)
                {
                    operationResult.ParseIdentityResult(identityResult);
                }
                else
                {
                    entity.Id = role.Id;
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionEntityFramework(exception);
            }

            return operationResult.Ok;
        }

        public override bool Delete(ZOperationResult operationResult, Role entity)
        {
            try
            {
                ApplicationRole role = IdentityHelperEF.RoleManager.FindById(entity.Id);
                if (role != null)
                {
                    IdentityResult identityResult = IdentityHelperEF.RoleManager.Delete(role);
                    if (!identityResult.Succeeded)
                    {
                        operationResult.ParseIdentityResult(identityResult);
                    }
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionEntityFramework(exception);
            }

            return operationResult.Ok;
        }

        public override bool Update(ZOperationResult operationResult, Role entity)
        {
            try
            {
                ApplicationRole role = IdentityHelperEF.RoleManager.FindById(entity.Id);
                role.Name = entity.Name;
                IdentityResult identityResult = IdentityHelperEF.RoleManager.Update(role);
                if (!identityResult.Succeeded)
                {
                    operationResult.ParseIdentityResult(identityResult);
                }
            }
            catch (Exception exception)
            {
                operationResult.ParseExceptionEntityFramework(exception);
            }

            return operationResult.Ok;
        }

        #endregion Methods
    }
}

gha_language: C#


text:
using System;

namespace Datadog.Trace
{
    internal class SpanEventArgs : EventArgs
    {
        public SpanEventArgs(Span span)
        {
            Span = span;
        }

        internal Span Span { get; }
    }
}

detected_licenses: MS-PL MIT Apache-2.0


text:
@techreport{cook_madison_2018,
 author = {Cook, Rachel and Hamadyk, Jill and Zeidenberg, Matthew and Rolston, Howard and Gardiner, Karen},
 copyright = {All rights reserved},
 file = {Madison Area Technical College Patient Care  Pathw.pdf:C\:\\Users\\mzeid\\Zotero\\storage\\GB7F243P\\Madison Area Technical College Patient Care  Pathw.pdf:application/pdf},
 institution = {Administration for Children and Families, U.S. Department of Health and Human Services},
 language = {en},
 month = {September},
 number = {2018-48},
 pages = {102},
 title = {Madison Area Technical College Patient Care  Pathway Program: Implementation and Early Impact Report},
 year = {2018}
}

repository: mzeidenberg/academic-kickstart

repo_name: mzeidenberg/academic-kickstart