// SPDX-License-Identifier: GPL-2.0-only
/* Test: virtio_ring: preserve VIRTIO_F_RING_RESET in transport features
 *
 * VIRTIO_F_RING_RESET is missing from the vring_transport_features()
 * whitelist, so it gets silently cleared during feature negotiation.
 *
 * sed -n '/^void vring_transport_features/,/^}/p' drivers/virtio/virtio_ring.c > extracted.c && gcc -Wall -Werror -o test0004 test0004.c && ./test0004
 */
#include <stdio.h>
#include <stdint.h>

typedef uint64_t u64;
struct virtio_device { u64 features; };

static void __virtio_clear_bit(struct virtio_device *vdev, unsigned int bit)
{
	vdev->features &= ~(1ULL << bit);
}

#define VIRTIO_TRANSPORT_F_START	28
#define VIRTIO_TRANSPORT_F_END		42
#define VIRTIO_RING_F_INDIRECT_DESC	28
#define VIRTIO_RING_F_EVENT_IDX		29
#define VIRTIO_F_VERSION_1		32
#define VIRTIO_F_ACCESS_PLATFORM	33
#define VIRTIO_F_RING_PACKED		34
#define VIRTIO_F_IN_ORDER		35
#define VIRTIO_F_ORDER_PLATFORM		36
#define VIRTIO_F_NOTIFICATION_DATA	38
#define VIRTIO_F_RING_RESET		40

#include "extracted.c"

int main(void)
{
	struct virtio_device vdev;

	vdev.features = (1ULL << VIRTIO_F_VERSION_1) | (1ULL << VIRTIO_F_RING_RESET);
	vring_transport_features(&vdev);

	if (!(vdev.features & (1ULL << VIRTIO_F_RING_RESET))) {
		printf("FAIL: VIRTIO_F_RING_RESET cleared during negotiation\n");
		return 1;
	}
	printf("PASS: VIRTIO_F_RING_RESET preserved\n");
	return 0;
}
