Пример #1
0
        public void PartiallyCopyExceptionHandling()
        {
            int bufferSize = 1024;

            using var exchangeBuffer =
                      Accelerator.AllocateExchangeBuffer <long>(bufferSize);
            using var stream = Accelerator.CreateStream();

            // CopyTo
            // Check lower bound for accelerator memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(stream, -1));

            // Check upper bound for accelerator memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(bufferSize + 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(stream, bufferSize + 1));

            // Check lower bound for cpu memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(-1, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(stream, -1, 0));

            // Check upper bound for cpu memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(bufferSize + 1, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(stream, bufferSize + 1, 0));

            // Check lower bound for the extent
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(0, 0, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(stream, 0, 0, 0));

            // Check upper bound for the extent
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(0, 0, bufferSize + 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(stream, 0, 0, bufferSize + 1));

            // Check if offset + extent > bufferSize
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(bufferSize, 0, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(bufferSize / 2, 0, bufferSize));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(0, bufferSize, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyToAccelerator(0, bufferSize / 2, bufferSize));

            // CopyFrom checks
            // Check lower bound for accelerator memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(stream, -1));

            // Check upper bound for accelerator memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(bufferSize + 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(stream, bufferSize + 1));

            // Check lower bound for cpu memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(-1, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(stream, -1, 0));

            // Check upper bound for cpu memory offset
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(bufferSize + 1, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(stream, bufferSize + 1, 0));

            // Check lower bound for the extent
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(0, 0, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(stream, 0, 0, 0));

            // Check upper bound for the extent
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(0, 0, bufferSize + 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(stream, 0, 0, bufferSize + 1));

            // Check if offset + extent > bufferSize
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(bufferSize, 0, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(bufferSize / 2, 0, bufferSize));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(0, bufferSize, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                        exchangeBuffer.CopyFromAccelerator(0, bufferSize / 2, bufferSize));
        }